mirror of
https://github.com/enduro2d/enduro2d.git
synced 2026-03-22 04:44:09 +07:00
editor selection basic API
This commit is contained in:
@@ -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_;
|
||||
};
|
||||
}
|
||||
|
||||
@@ -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:
|
||||
|
||||
@@ -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();
|
||||
}
|
||||
}
|
||||
|
||||
@@ -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);
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user