Example #1
0
void SelectionPlugin::onMouseButtonRelease( const MouseButtonEvent& event )
{
	if( event.button != MouseButton::Left )
		return;

	SceneDocument* sceneDocument = (SceneDocument*) editor->getDocument();
	sceneDocument->getRenderWindow()->setCursorCapture(false);

	editor->getDocument()->getWindow()->flagRedraw();

	SelectionOperation* selection = nullptr;

	if(selections->dragRectangle)
		selection = processDragSelection(event);
	else
		selection = processSelection(event);

	if( !selection ) return;

	const SelectionCollection& selected = selections->getSelections();

	// Prevent duplication of selection events.
	if( selected.isSame(selection->selections) ) 
	{
		LogDebug("Ignoring duplicated selection");
		Deallocate(selection);
		return;
	}

	selection->redo();

	UndoManager* undoManager = sceneDocument->getUndoManager();
	undoManager->registerOperation(selection);
}
Example #2
0
SelectionOperation* SelectionPlugin::createDeselection()
{
	// If there is a current selection, and the user pressed the mouse,
	// then we need to unselect everything that is currently selected.

	SelectionOperation* selection = CreateSelectionOperation("Deselection");
	selection->setPreviousSelections( selections->getSelections() );

	return selection;
}
Example #3
0
SelectionOperation* CreateEntitySelectionOperation(const EntityPtr& entity)
{
	SelectionManager* selections = GetPlugin<SelectionPlugin>()->getSelectionManager();
	if( !selections ) return nullptr;

	SelectionOperation* selection = CreateSelectionOperation("Entity selection");
	selection->selections.addEntity(entity);
	selection->setPreviousSelections( selections->getSelections() );

	return selection;
}
Example #4
0
void SelectionPlugin::onUndoOperation( const UndoOperationPtr& operation )
{
	assert( operation != nullptr );

	Class* klass = operation->getType();
	
	if( !ClassInherits(klass, ReflectionGetType(SelectionOperation)) )
		return;

	SelectionOperation* selection = RefCast<SelectionOperation>(operation).get();
	selection->redo();
}
Example #5
0
SelectionOperation* SelectionPlugin::processDragSelection(const MouseButtonEvent& event)
{
	SceneDocument* sceneDocument = (SceneDocument*) editor->getDocument();
	Scene* scene = sceneDocument->scene.get();
	
	RenderView* view = sceneDocument->sceneWindow->getView();
	Camera* camera = sceneDocument->sceneWindow->getCamera().get();

	Overlay* overlay = selections->dragRectangle->getComponent<Overlay>().get();
	const Vector3& pos = overlay->getOffset();
	const Vector3& size = overlay->getSize();

	Frustum pickVolume = camera->getVolume(pos.x, pos.x+size.x, pos.y, pos.y+size.y);

	RayQueryList list;
	scene->doRayVolumeQuery(pickVolume, list);

	sceneDocument->editorScene->entities.remove(selections->dragRectangle);
	selections->dragRectangle.reset();

	if( list.empty() )
	{
		SelectionOperation* selection = createDeselection();
		return selection;
	}

#if 0
	// If we are in additive mode, don't create a new selection.
	if( selected && additiveMode )
		selection = selected;
#endif

	// If there is no current selection, create a new one.
	SelectionOperation* selection = CreateSelectionOperation("Drag Selection");
	selection->setPreviousSelections( selections->getSelections() );

	SelectionCollection& selections = selection->selections;

	for( size_t i = 0; i < list.size(); i++ )
	{
		// Add the picked selection to the selection collection.
		selections.addEntity( list[i].entity );
	}

#if 0
	if( selected && !additiveMode )
		selection->previous = selected->selections;
#endif

	return selection;
}
Example #6
0
SelectionOperation* SelectionPlugin::processSelection(const MouseButtonEvent& event)
{
	SelectionOperation* selection = nullptr;

	EntityPtr entity;
	
	if( !getPickEntity(event.x, event.y, entity) )
	{
		selection = createDeselection();
		return selection;
	}
	
	selection = CreateSelectionOperation("Selection");
	selection->selections.addEntity(entity);
	selection->setPreviousSelections( selections->getSelections() );

	return selection;
}