Peoplemon  0.1.0
Peoplemon 3 game source documentation
LightSlider.cpp
Go to the documentation of this file.
2 
3 namespace editor
4 {
5 namespace component
6 {
7 using namespace bl::gui;
8 
9 LightSlider::Ptr LightSlider::create(const std::string& prompt, const ChangeCb& cb) {
10  return Ptr(new LightSlider(prompt, cb));
11 }
12 
13 LightSlider::LightSlider(const std::string& p, const ChangeCb& cb)
14 : Box(LinePacker::create(LinePacker::Horizontal, 4.f)) {
15  Box::Ptr col = Box::create(LinePacker::create(LinePacker::Vertical, 2.f));
16  Box::Ptr row = Box::create(LinePacker::create(LinePacker::Horizontal, 0.f));
17  row->pack(Label::create("Dark"), false, true);
18  prompt = Label::create(p);
19  row->pack(prompt, true, true);
20  row->pack(Label::create("Bright"));
21  col->pack(row, true, false);
22 
23  slider = Slider::create(Slider::Horizontal);
24  slider->setRequisition({125.f, 20.f});
25  slider->getSignal(Event::ValueChanged).willAlwaysCall(std::bind(cb));
26  slider->getSignal(Event::ValueChanged).willAlwaysCall([this](const Event&, Element*) {
27  preview->setLightLevel(getLightLevel());
28  });
29  col->pack(slider, true, false);
30  pack(col, true, false);
31 
32  preview = LightPreview::create({80.f, 80.f});
33  pack(preview);
34 }
35 
36 std::uint8_t LightSlider::getLightLevel() const {
37  return static_cast<std::uint8_t>(slider->getValue() * 255.f);
38 }
39 
40 void LightSlider::setLightLevel(std::uint8_t level) {
41  slider->setValue(static_cast<float>(level) / 255.f, false);
42  preview->setLightLevel(level);
43 }
44 
45 void LightSlider::setPrompt(const std::string& p) { prompt->setText(p); }
46 
47 } // namespace component
48 } // namespace editor
All classes and functionality used for implementing the game editor.
Definition: Tile.hpp:11
static Ptr create(const sf::Vector2f &size)
Create a new LightPreview component.
Definition: LightPreview.cpp:9
void setLightLevel(std::uint8_t level)
Sets the selected light level.
Definition: LightSlider.cpp:40
std::shared_ptr< LightSlider > Ptr
Definition: LightSlider.hpp:19
static Ptr create(const std::string &prompt, const ChangeCb &onChange)
Create a new light level slider.
Definition: LightSlider.cpp:9
std::function< void()> ChangeCb
Definition: LightSlider.hpp:20
void setPrompt(const std::string &prompt)
Sets the text prompt that is displayed.
Definition: LightSlider.cpp:45
std::uint8_t getLightLevel() const
Returns the currently selected light level.
Definition: LightSlider.cpp:36