chore: add nested PickCallbackHandler to Gizmo
This commit is contained in:
@@ -31,6 +31,30 @@ class Gizmo {
|
||||
|
||||
enum Axis { X, Y, Z};
|
||||
|
||||
class PickCallbackHandler {
|
||||
public:
|
||||
PickCallbackHandler(Gizmo* gizmo, void (*callback)(EntityId entityId, int x, int y)) : _gizmo(gizmo), _callback(callback) {};
|
||||
void handle(filament::View::PickingQueryResult const &result) {
|
||||
auto x = static_cast<int32_t>(result.fragCoords.x);
|
||||
auto y= static_cast<int32_t>(result.fragCoords.y);
|
||||
for(int i = 4; i < 7; i++) {
|
||||
if(_gizmo->_entities[i] == result.renderable) {
|
||||
_gizmo->highlight(_gizmo->_entities[i - 4]);
|
||||
_callback(Entity::smuggle(_gizmo->_entities[i - 4]), x, y);
|
||||
return;
|
||||
}
|
||||
}
|
||||
_gizmo->unhighlight();
|
||||
_callback(0, x, y);
|
||||
delete(this);
|
||||
}
|
||||
|
||||
private:
|
||||
Gizmo* _gizmo;
|
||||
void (*_callback)(EntityId entityId, int x, int y);
|
||||
|
||||
};
|
||||
|
||||
public:
|
||||
Gizmo(Engine& engine, View *view, Scene *scene);
|
||||
~Gizmo();
|
||||
|
||||
@@ -359,20 +359,11 @@ void Gizmo::destroy()
|
||||
_engine.destroy(_material);
|
||||
}
|
||||
|
||||
|
||||
void Gizmo::pick(uint32_t x, uint32_t y, void (*callback)(EntityId entityId, int x, int y))
|
||||
{
|
||||
auto * gizmo = this;
|
||||
_view->pick(x, y, [=](filament::View::PickingQueryResult const &result) {
|
||||
for(int i = 4; i < 7; i++) {
|
||||
if(_entities[i] == result.renderable) {
|
||||
gizmo->highlight(_entities[i - 4]);
|
||||
callback(Entity::smuggle(_entities[i - 4]), x, y);
|
||||
return;
|
||||
}
|
||||
}
|
||||
gizmo->unhighlight();
|
||||
callback(0, x, y);
|
||||
auto handler = new Gizmo::PickCallbackHandler(this, callback);
|
||||
_view->pick(x, y, [=](filament::View::PickingQueryResult const &result) {
|
||||
handler->handle(result);
|
||||
});
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user