-
Notifications
You must be signed in to change notification settings - Fork 7
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add a camera rotation sensitivity slider to the main tool window - this will probably be moved to a settings window at some point. The slider is also currently unlabeled. The sensitivity currently scales the sensitivity between dividing by 200 (low) and by 25 (high). Also fixed an issue where alpha blending wasn't working - it was cutting holes through the render target stack all the way down to the clear colour. Controls can now handle input. The input code needs to move out to its own classes though, it shouldn't be in the controls themselves as there is currently some up and down movement for notifying about which control has the focus etc. #20
- Loading branch information
Showing
11 changed files
with
263 additions
and
32 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,63 @@ | ||
#include "Slider.h" | ||
#include <algorithm> | ||
|
||
namespace trview | ||
{ | ||
namespace ui | ||
{ | ||
namespace | ||
{ | ||
const float BlobWidth = 10.f; | ||
} | ||
|
||
Slider::Slider(Point position, Size size) | ||
: Window(position, size, Colour(0, 0, 0, 0)) | ||
{ | ||
// Create the child windows (and store them for later manipulation). | ||
auto line = std::make_unique<Window>( | ||
Point(BlobWidth, size.height / 2.f - 1.f), | ||
Size(size.width - BlobWidth * 2.f, 2.f), | ||
Colour(1, 0, 0, 0)); | ||
|
||
auto blob = std::make_unique<Window>( | ||
Point(0, 0), | ||
Size(BlobWidth, size.height), | ||
Colour(1.0f, 0.2f, 0.2f, 0.2f)); | ||
|
||
_blob = blob.get(); | ||
|
||
add_child(std::move(line)); | ||
add_child(std::move(blob)); | ||
|
||
set_blob_position(Point(0, 0)); | ||
} | ||
|
||
bool Slider::clicked(Point position) | ||
{ | ||
set_blob_position(position); | ||
return true; | ||
} | ||
|
||
bool Slider::move(Point position) | ||
{ | ||
if (focus_control() == this) | ||
{ | ||
set_blob_position(position); | ||
return true; | ||
} | ||
return false; | ||
} | ||
|
||
void Slider::set_blob_position(Point position) | ||
{ | ||
const float SliderSize = size().width - BlobWidth * 2; | ||
const float percentage = std::min(1.0f, std::max(0.0f, (position.x - BlobWidth) / SliderSize)); | ||
const float x = BlobWidth + percentage * SliderSize - BlobWidth * 0.5f; | ||
|
||
const auto pos = _blob->position(); | ||
_blob->set_position(Point(x, pos.y)); | ||
|
||
on_value_changed.raise(percentage); | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,27 @@ | ||
#pragma once | ||
|
||
#include "Window.h" | ||
#include <trview.common/Event.h> | ||
|
||
namespace trview | ||
{ | ||
namespace ui | ||
{ | ||
class Slider : public Window | ||
{ | ||
public: | ||
Slider(Point position, Size size); | ||
virtual ~Slider() = default; | ||
|
||
Event<float> on_value_changed; | ||
protected: | ||
virtual bool clicked(Point position) override; | ||
virtual bool move(Point position) override; | ||
private: | ||
void set_blob_position(Point position); | ||
|
||
float _value{ 0.5f }; | ||
ui::Control* _blob; | ||
}; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.