Esempio n. 1
0
void Viewport::MouseDown(const Helium::MouseButtonInput& input)
{
	// reset drag mode
	m_DragMode = DragModes::None;

	// are we going to allow entering select drag?
	bool allowSelection = true;

	// if the camera modifier key is down
	if (input.AltIsDown())
	{
		m_Cameras[m_CameraMode].MouseDown( input );

		// camera now owns the drag
		m_DragMode = DragModes::Camera;

		// do NOT allow selection while moving the camera
		allowSelection = false;

		// Save the previous view before it is updated
		UpdateCameraHistory();   
	}
	else if (m_Tool) // else if we have a tool object
	{
		// hit test the tool, and if we intersect or its a tool modifier mouse key
		if (m_Tool->MouseDown( input ) || input.MiddleDown() || input.RightDown())
		{
			// the tool now owns this drag
			m_DragMode = DragModes::Tool;
		}
		else
		{
			// we can still allow selection if it didn't hit he tool
			allowSelection = m_Tool->AllowSelection();
		}
	}

	// if its the left key if we are still looking for a selection
	if ( (input.LeftIsDown() || input.MiddleIsDown()) && m_DragMode == DragModes::None && allowSelection )
	{
		// we are selecting
		m_DragMode = DragModes::Select;

		// reset point trackers
		m_Start = Point (input.GetPosition().x, input.GetPosition().y);
		m_End = Point (input.GetPosition().x, input.GetPosition().y);

		// reset selection frame
		m_SelectionFrame->m_Start = m_Start;
		m_SelectionFrame->m_End = m_End;
		m_SelectionFrame->Update();

		// if we are highlighting
		if ( m_Highlighting )
		{
			// clear the previously highlighted set
			m_ClearHighlight.Raise( ClearHighlightArgs (false) );
		}
	}
}
Esempio n. 2
0
void Viewport::MouseUp( const Helium::MouseButtonInput& input )
{
	// have we completed a drag?
	bool dragComplete = false;

	switch (m_DragMode)
	{
	case DragModes::None:
		{
			if (!m_Tool && input.RightUp())
			{
				m_End = Point (input.GetPosition().x, input.GetPosition().y);
				m_SelectionFrame->m_End = m_End;
				m_SelectionFrame->Update();

				PickVisitor* pick = NULL;

				SelectionTargetMode targetMode = SelectionTargetModes::Single;

				if (m_SelectionFrame->m_Start.x == m_SelectionFrame->m_End.x && m_SelectionFrame->m_Start.y == m_SelectionFrame->m_End.y)
				{
					pick = new FrustumLinePickVisitor (&m_Cameras[m_CameraMode], m_SelectionFrame->m_Start.x, m_SelectionFrame->m_Start.y);
					targetMode = SelectionTargetModes::Single;
				}
				else 
				{
					Frustum worldSpaceFrustum;
					if ( m_Cameras[m_CameraMode].ViewportToFrustum( (float32_t)m_SelectionFrame->m_Start.x, (float32_t)m_SelectionFrame->m_Start.y, (float32_t)m_SelectionFrame->m_End.x, (float32_t)m_SelectionFrame->m_End.y, worldSpaceFrustum) )
					{
						Point center ( m_SelectionFrame->m_Start + m_SelectionFrame->m_End / 2 );

						Line line;
						m_Cameras[m_CameraMode].ViewportToLine( (float32_t)center.x, (float32_t)center.y, line);

						pick = new FrustumLinePickVisitor(&m_Cameras[m_CameraMode], line, worldSpaceFrustum );
						targetMode = SelectionTargetModes::Multiple;
					}                   
				}

				if ( pick )
				{
					m_Select.Raise( SelectArgs (pick, SelectionModes::Manifest, targetMode) );
					delete pick;
					pick = NULL;
				}

				// our drag is complete now
				dragComplete = true;
			}

			break;
		}

	case DragModes::Select:
		{
			if (input.LeftUp() || input.MiddleUp())
			{
				m_End = Point (input.GetPosition().x, input.GetPosition().y);
				m_SelectionFrame->m_End = m_End;
				m_SelectionFrame->Update();

				PickVisitor* pick = NULL;

				SelectionTargetMode targetMode = SelectionTargetModes::Single;

				if (m_SelectionFrame->m_Start.x == m_SelectionFrame->m_End.x && m_SelectionFrame->m_Start.y == m_SelectionFrame->m_End.y)
				{
					pick = new FrustumLinePickVisitor (&m_Cameras[m_CameraMode], m_SelectionFrame->m_Start.x, m_SelectionFrame->m_Start.y);
					targetMode = SelectionTargetModes::Single;
				}
				else 
				{
					Frustum worldSpaceFrustum;

					if ( m_Cameras[m_CameraMode].ViewportToFrustum( (float32_t)m_SelectionFrame->m_Start.x, (float32_t)m_SelectionFrame->m_Start.y, (float32_t)m_SelectionFrame->m_End.x, (float32_t)m_SelectionFrame->m_End.y, worldSpaceFrustum) )
					{
						Point center ( m_SelectionFrame->m_Start + m_SelectionFrame->m_End / 2 );

						Line line;
						m_Cameras[m_CameraMode].ViewportToLine( (float32_t)center.x, (float32_t)center.y, line);

						pick = new FrustumLinePickVisitor (&m_Cameras[m_CameraMode], line, worldSpaceFrustum); 
						targetMode = SelectionTargetModes::Multiple;
					}
				}

				if ( pick )
				{
					SelectionModes::SelectionMode selectMode;

					if (input.MiddleUp())
					{
						selectMode = SelectionModes::Manifest;
					}
					else
					{
						if ( input.CtrlIsDown() )
						{
							if ( input.ShiftIsDown())
							{
								selectMode = SelectionModes::Add;
							}
							else
							{
								selectMode = SelectionModes::Remove;
							}
						}
						else
						{
							if ( input.ShiftIsDown())
							{
								selectMode = SelectionModes::Toggle;
							}
							else
							{
								selectMode = SelectionModes::Replace;
							}
						}
					}

					m_Select.Raise( SelectArgs (pick, selectMode, targetMode) );
					delete pick;
					pick = NULL;
				}

				// our drag is complete now
				dragComplete = true;
			}

			break;
		}

	case DragModes::Camera:
		{
			if (input.AltIsDown())
			{
				m_Cameras[m_CameraMode].MouseUp( input );
			}

			break;
		}

	default:
		{
			if (m_Tool)
			{
				m_Tool->MouseUp( input );
			}

			break;
		}
	}

	if (dragComplete)
	{
		m_DragMode = DragModes::None;
	}
}