editor selection basic API

This commit is contained in:
2019-12-09 06:16:35 +07:00
parent 531c29f4fa
commit 5d32e5be64
4 changed files with 48 additions and 5 deletions

View File

@@ -8,11 +8,21 @@
#include "_high.hpp"
#include "gobject.hpp"
namespace e2d
{
class editor final : public module<editor> {
public:
editor();
~editor() noexcept final;
void select(const gobject& go);
bool is_selected(const gobject& go) const noexcept;
void unselect(const gobject& go) noexcept;
void clear_selection() noexcept;
private:
mutable std::mutex mutex_;
flat_set<gobject> selection_;
};
}

View File

@@ -59,6 +59,10 @@ namespace e2d
state_iptr state_;
};
bool operator<(const gobject& l, const gobject& r) noexcept;
bool operator==(const gobject& l, const gobject& r) noexcept;
bool operator!=(const gobject& l, const gobject& r) noexcept;
template < typename T >
class gcomponent final {
public:

View File

@@ -9,11 +9,6 @@
#include <enduro2d/high/widgets/hierarchy_widget.hpp>
#include <enduro2d/high/widgets/inspector_widget.hpp>
namespace
{
using namespace e2d;
}
namespace e2d
{
editor::editor() {
@@ -24,4 +19,24 @@ namespace e2d
}
editor::~editor() noexcept = default;
void editor::select(const gobject& go) {
std::lock_guard<std::mutex> guard(mutex_);
selection_.insert(go);
}
bool editor::is_selected(const gobject& go) const noexcept {
std::lock_guard<std::mutex> guard(mutex_);
return selection_.find(go) != selection_.end();
}
void editor::unselect(const gobject& go) noexcept {
std::lock_guard<std::mutex> guard(mutex_);
selection_.erase(go);
}
void editor::clear_selection() noexcept {
std::lock_guard<std::mutex> guard(mutex_);
selection_.clear();
}
}

View File

@@ -42,4 +42,18 @@ namespace e2d
E2D_ASSERT(valid());
return state_->raw_entity();
}
bool operator<(const gobject& l, const gobject& r) noexcept {
return (!l && r)
|| (l && r && l.raw_entity() < r.raw_entity());
}
bool operator==(const gobject& l, const gobject& r) noexcept {
return (!l && !r)
|| (l && r && l.raw_entity() == r.raw_entity());
}
bool operator!=(const gobject& l, const gobject& r) noexcept {
return !(l == r);
}
}