Skip to content

Commit

Permalink
Better toolbox
Browse files Browse the repository at this point in the history
  • Loading branch information
johnBuffer committed Dec 8, 2021
1 parent c531142 commit 55169a9
Show file tree
Hide file tree
Showing 6 changed files with 57 additions and 31 deletions.
5 changes: 3 additions & 2 deletions include/editor/GUI/named_container.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,8 @@ struct NamedContainer : public Container
SPtr<TextLabel> label;
SPtr<Container> root;

uint8_t background_intensity = 220;

bool show_root = true;

NamedContainer(const std::string& name, Container::Orientation orientation = Container::Orientation::Vertical)
Expand Down Expand Up @@ -85,8 +87,7 @@ struct NamedContainer : public Container
{
const float angle_radius = 10.0f;
RoundedRectangle background(size, position, angle_radius);
const uint8_t background_intensity = 220;
background.setFillColor(sf::Color(background_intensity, background_intensity, background_intensity));
background.setFillColor({background_intensity, background_intensity, background_intensity});
GUI::Item::draw(target, background);
}

Expand Down
5 changes: 2 additions & 3 deletions include/editor/editor_scene.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@ struct EditorScene : public GUI::Scene

renderer = create<WorldView>(toVector2f(window_size), simulation, control_state);

toolbox = create<Toolbox>(sf::Vector2f(350.0f, to<float>(window_size.y)));
toolbox = create<Toolbox>(sf::Vector2f{350.0f, to<float>(window_size.y)}, sf::Vector2f{root.padding, root.padding});
// Add display options
display_controls = create<DisplayOption>(control_state);
watch(display_controls, [this](){
Expand All @@ -79,7 +79,6 @@ struct EditorScene : public GUI::Scene
this->tool_selector->resetCallback();
}
});
//tools_toggle->setState(false);

tools->header->addItem(tools_toggle);
toolbox->addItem(tools);
Expand All @@ -103,7 +102,7 @@ struct EditorScene : public GUI::Scene
auto time_controls = create<TimeController>();
watch(time_controls, [this, time_controls](){
this->renderer->current_time_state = time_controls->current_state;
if (time_controls->current_state == TimeController::State::Speed) {
if (time_controls->tool_speed->getState()) {
this->window.setFramerateLimit(0);
} else {
this->window.setFramerateLimit(60);
Expand Down
4 changes: 3 additions & 1 deletion include/editor/slider.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -108,7 +108,9 @@ struct SliderLabel : public GUI::Container
void render(sf::RenderTarget& target) override
{
const float angle_radius = 5.0f;
GUI::Item::draw(target, GUI::RoundedRectangle(size, position, angle_radius));
GUI::RoundedRectangle background(size, position, angle_radius);
background.setFillColor({200, 200, 200});
GUI::Item::draw(target, background);
}
};

Expand Down
34 changes: 20 additions & 14 deletions include/editor/time_control/time_controller.hpp
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
#pragma once
#include "editor/tool_selector.hpp"
#include "editor/GUI/toggle.hpp"


namespace edtr
{
Expand All @@ -10,33 +12,41 @@ struct TimeController : public GUI::NamedContainer
{
Play,
Pause,
Speed
};

State current_state = State::Pause;

SPtr<ToolOption> tool_pause;
SPtr<ToolOption> tool_play;
SPtr<ToolOption> tool_speed;
SPtr<GUI::NamedToggle> tool_speed;

TimeController()
: GUI::NamedContainer("Time Control", Container::Orientation::Horizontal)
, current_state(State::Pause)
{
setWidth(180.0f);

root->setHeight(30.0f, GUI::Size::Fixed);
tool_pause = create<ToolOption>("Pause", [this](){
size_type.x = GUI::Size::FitContent;
size_type.y = GUI::Size::FitContent;
root->size_type.x = GUI::Size::FitContent;
root->size_type.y = GUI::Size::FitContent;

tool_pause = create<ToolOption>("PAUSE", [this](){
current_state = State::Pause;
select(State::Pause);
});
tool_play = create<ToolOption>("Play", [this](){
tool_pause->color = {255, 255, 230};
tool_pause->setWidth(70.0f);

tool_play = create<ToolOption>("PLAY", [this](){
current_state = State::Play;
select(State::Play);
});
tool_speed = create<ToolOption>("Speed", [this](){
current_state = State::Speed;
select(State::Speed);
tool_play->color = {230, 255, 230};
tool_play->setWidth(70.0f);

tool_speed = create<GUI::NamedToggle>("Full Speed");
tool_speed->setWidth(70.0f);
watch(tool_speed, [this]{
notifyChanged();
});

// Add items
Expand All @@ -51,7 +61,6 @@ struct TimeController : public GUI::NamedContainer
{
tool_pause->reset();
tool_play->reset();
tool_speed->reset();
}

void select(State option)
Expand All @@ -65,9 +74,6 @@ struct TimeController : public GUI::NamedContainer
case State::Play:
tool_play->select();
break;
case State::Speed:
tool_speed->select();
break;
}
notifyChanged();
}
Expand Down
38 changes: 28 additions & 10 deletions include/editor/toolbox.hpp
Original file line number Diff line number Diff line change
@@ -1,28 +1,46 @@
#pragma once
#include "GUI/button.hpp"
#include "editor/color_picker/color_picker.hpp"
#include "GUI/container.hpp"
#include "editor/GUI/named_container.hpp"
#include "editor/GUI/toggle.hpp"
#include "slider.hpp"
#include "common/dynamic_blur.hpp"


namespace edtr
{

struct Toolbox : public GUI::Container
struct Toolbox : public GUI::NamedContainer
{
explicit
Toolbox(sf::Vector2f size_, sf::Vector2f position_ = {})
: GUI::Container(GUI::Container::Orientation::Vertical, size_, position_)
{}

void render(sf::RenderTarget& target) override
: GUI::NamedContainer("Toolbox", GUI::Container::Orientation::Vertical)
{
sf::RectangleShape background(size);
background.setPosition(position);
background.setFillColor(sf::Color(100, 100, 100, 200));
GUI::Item::draw(target, background);
header->addItem(create<GUI::EmptyItem>());
auto tools_toggle = create<GUI::Toggle>();
tools_toggle->color_on = {240, 180, 0};
tools_toggle->setState(true);
watch(tools_toggle, [this, tools_toggle]{
if (tools_toggle->state) {
showRoot();
} else {
hideRoot();
}
});
header->addItem(tools_toggle);

setPosition(position_);
background_intensity = 180;
setWidth(size_.x);
}

// void render(sf::RenderTarget& target) override
// {
// sf::RectangleShape background(size);
// background.setPosition(position);
// background.setFillColor(sf::Color(100, 100, 100, 200));
// GUI::Item::draw(target, background);
// }
};

}
2 changes: 1 addition & 1 deletion include/editor/world_view.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -94,7 +94,7 @@ struct WorldView : GUI::Item
void update() override
{
const float dt = 0.016f;
if (current_time_state == TimeController::State::Play || current_time_state == TimeController::State::Speed) {
if (current_time_state == TimeController::State::Play) {
simulation.update(dt);
}
}
Expand Down

0 comments on commit 55169a9

Please sign in to comment.