Beispiel #1
0
void TitleBar::MouseDraggedOutside(const MouseEvent& lEvent)
{
	if(!m_bFirstOutsideDrag)
	{
		m_lastX = lEvent.GetX();
		m_lastY = lEvent.GetY();
		m_bFirstOutsideDrag = true;
	}

	if(m_pParent->m_bAllowMoving)
	{
		if(lEvent.GetSource() == this)
		{
			if(m_bDragging)
			{
				int lNewX = lEvent.GetX();
				int lNewY = lEvent.GetY();

				int l_ChangeX = lNewX - m_lastX;
				int l_ChangeY = lNewY - m_lastY;

				if(l_ChangeX == 0 && l_ChangeY == 0)
					return;

				m_nextX = GetParent()->GetLocationOnScreen().m_x + l_ChangeX;
				m_nextY = GetParent()->GetLocationOnScreen().m_y + l_ChangeY;
				GetParent()->SetLocation(m_nextX, m_nextY);

				m_lastX = lNewX;
				m_lastY = lNewY;
			}
		}
	}

	OnMouseDraggedOutside();
}
Beispiel #2
0
void MenuItem::MouseReleased(const MouseEvent& lEvent)
{
	if(!IsParentMenuOpen())
	{
		return;
	}

	Menu* lpParentMenu = (Menu* )GetParent();
	
	// Make sure that we are inside the bounds of the parent menu
	if(lpParentMenu->GetPullDownMenuParent() != NULL)
	{
		int lTextHeight = m_pRenderer->GetFreeTypeTextHeight(lpParentMenu->GetPullDownMenuParent()->GetGUIFont(), "%s", lpParentMenu->GetMenuTitle().c_str());
		int lMenuHeight = lTextHeight + (lpParentMenu->GetMenuItemSpacer() * 2);
		int lFullMenuDisplayHeight = lpParentMenu->GetPullDownMenuParent()->GetMaxNumItemsDisplayed() * lMenuHeight;

		Point location = lpParentMenu->GetPullDownMenuParent()->GetLocation();
		for(Component* parent = lpParentMenu->GetPullDownMenuParent()->GetParent(); parent != 0;)
		{
			Point parentLocation = parent->GetLocation();

			location.m_x += parentLocation.m_x;
			location.m_y += parentLocation.m_y;

			parent = parent->GetParent();
		}
		int lMenuX = location.m_x;
		int lMenuY = location.m_y - lFullMenuDisplayHeight;
		int lMenuWidth = lpParentMenu->GetBiggestWidth()+ (lpParentMenu->GetMenuItemSpacer() * 2);

		if(lEvent.GetX() > lMenuX && lEvent.GetX() <= lMenuX+lMenuWidth && lEvent.GetY() > lMenuY && lEvent.GetY() <= lMenuY+lFullMenuDisplayHeight)
		{
			// Close the menu, since we have clicked this menu item
			lpParentMenu->CloseMenu();

			SetHover(false);
			SetSelected(false);

			// Signal that we have pressed this menu item
			MenuItemPressed();
		}
	}


	FocusManager::GetInstance()->SetFocusOwner(0);

	OnMouseReleased();
}
Beispiel #3
0
void TitleBar::MouseDragged(const MouseEvent& lEvent)
{
	// Don't allow moving if we have disabled this
	if(m_pParent->m_bAllowMoving)
	{
		if(lEvent.GetSource() == this)
		{
			if(m_bDragging)
			{
				m_nextX = GetParent()->GetLocationOnScreen().m_x + lEvent.GetX();
				m_nextY = GetParent()->GetLocationOnScreen().m_y + lEvent.GetY();
				GetParent()->SetLocation(m_nextX, m_nextY);
			}
		}
	}

	OnMouseDragged();
}
Beispiel #4
0
void Slider::MouseDragged(const MouseEvent& lEvent)
{
	if(m_bDragging)
	{
		int l_ChangeX = lEvent.GetX();
		int l_ChangeY = lEvent.GetY();

		if(l_ChangeX == 0 && l_ChangeY == 0)
			return;

		float lValueChange;
		if(m_eSliderDirection == ESliderDirection_Horizontal)
		{
			lValueChange = static_cast<float>(l_ChangeX) * ((m_maxValue - m_minValue) / (static_cast<float>(m_dimensions.m_width) - static_cast<float>(m_sliderWidth)));
		}
		else //if(m_eSliderDirection == ESliderDirection_Vertical)
		{
			lValueChange = static_cast<float>(l_ChangeY) * ((m_maxValue - m_minValue) / (static_cast<float>(m_dimensions.m_height) - static_cast<float>(m_sliderWidth)));
		}

		// Store the value before we change it, to see if we have actually changed the value
		float lValueBefore = m_currentValue;

		m_currentValue += lValueChange;

		if(m_currentValue > m_maxValue)
		{
			m_currentValue = m_maxValue;
		}
		if(m_currentValue < m_minValue)
		{
			m_currentValue = m_minValue;
		}

		if(m_currentValue != lValueBefore)
		{
			ValueChanged();
		}
	}
}
Beispiel #5
0
void MenuItem::MouseEntered(const MouseEvent& lEvent)
{
	if(!IsParentMenuOpen())
	{
		return;
	}

	Menu* lpParentMenu = (Menu* )GetParent();

	// Make sure that we are inside the bounds of the parent menu
	if(lpParentMenu->GetPullDownMenuParent() != NULL)
	{
		int lTextHeight = m_pRenderer->GetFreeTypeTextHeight(lpParentMenu->GetPullDownMenuParent()->GetGUIFont(), "%s", lpParentMenu->GetMenuTitle().c_str());
		int lMenuHeight = lTextHeight + (lpParentMenu->GetMenuItemSpacer() * 2);
		int lFullMenuDisplayHeight = lpParentMenu->GetPullDownMenuParent()->GetMaxNumItemsDisplayed() * lMenuHeight;

		Point location = lpParentMenu->GetPullDownMenuParent()->GetLocation();
		for(Component* parent = lpParentMenu->GetPullDownMenuParent()->GetParent(); parent != 0;)
		{
			Point parentLocation = parent->GetLocation();

			location.m_x += parentLocation.m_x;
			location.m_y += parentLocation.m_y;

			parent = parent->GetParent();
		}
		int lMenuX = location.m_x;
		int lMenuY = location.m_y - lFullMenuDisplayHeight;
		int lMenuWidth = lpParentMenu->GetBiggestWidth()+ (lpParentMenu->GetMenuItemSpacer() * 2);

		if(lEvent.GetX() > lMenuX && lEvent.GetX() <= lMenuX+lMenuWidth && lEvent.GetY() > lMenuY && lEvent.GetY() <= lMenuY+lFullMenuDisplayHeight)
		{
			SetHover(true);

			OnMouseEnter();
		}
	}
}
Beispiel #6
0
void Slider::MouseReleased(const MouseEvent& lEvent)
{
	if(!m_bDragging && m_bPressedBar)
	{
		int lSliderWidth;
		int lSliderHeight;

		int lBarX;
		int lBarY;
		int lBarWidth;
		int lBarHeight;

		if(m_eSliderDirection == ESliderDirection_Horizontal)
		{
			lBarX = GetLocationOnScreen().m_x + (m_sliderWidth / 2);
			lBarY = GetLocationOnScreen().m_y + (m_dimensions.m_height / 2) - (m_barHeight / 2);
			lBarWidth = m_dimensions.m_width - m_sliderWidth;
			lBarHeight = m_barHeight;

			lSliderWidth = m_sliderWidth;
			lSliderHeight = m_dimensions.m_height;
		}
		else //if(m_eSliderDirection == ESliderDirection_Vertical)
		{
			lBarX = GetLocationOnScreen().m_x + (m_dimensions.m_width / 2) - (m_barHeight / 2);
			lBarY = GetLocationOnScreen().m_y + (m_sliderWidth / 2);
			lBarWidth = m_barHeight;
			lBarHeight = m_dimensions.m_height - m_sliderWidth;

			lSliderWidth = m_dimensions.m_width;
			lSliderHeight = m_sliderWidth;
		}

		int mouseX = lEvent.GetX();
		int mouseY = lEvent.GetY();

		// Store the value before we change it, to see if we have actually changed the value
		float lValueBefore = m_currentValue;

		if((mouseX >= lBarX) && (mouseX < lBarX + lBarWidth) && (mouseY >= lBarY) && (mouseY < lBarY + lBarHeight))
		{
			// Check to see if we have clicked on the bar to 'zoom' to a location

			if(m_eSliderDirection == ESliderDirection_Horizontal)
			{
				int lRelativeX = mouseX - GetLocationOnScreen().m_x;
				float ratio = (float)lRelativeX / (float)lBarWidth;
				m_currentValue = m_minValue + ((m_maxValue - m_minValue) * ratio);
			}
			else //if(m_eSliderDirection == ESliderDirection_Vertical)
			{
				int lRelativeY = mouseY - GetLocationOnScreen().m_y;
				float ratio = (float)lRelativeY / (float)lBarWidth;
				m_currentValue = m_minValue + ((m_maxValue - m_minValue) * ratio);
			}
		}

		if(m_currentValue != lValueBefore)
		{
			ValueChanged();
		}

		m_bPressedBar = false;
	}

	m_bDragging = false;
	m_bPressedBar = false;

	// Allow dragging again now, since we have released the button, we can now check for dragging again on pressing
	m_bAllowDragging = true;

	// Allow releasing on the bar now, we can now check for this again on pressing
	m_bAllowReleasingOnBar = true;

	OnMouseReleased();
}
Beispiel #7
0
void Slider::MousePressed(const MouseEvent& lEvent)
{
	int lSliderX;
	int lSliderY;
	int lSliderWidth;
	int lSliderHeight;

	int lBarX;
	int lBarY;
	int lBarWidth;
	int lBarHeight;

	if(m_eSliderDirection == ESliderDirection_Horizontal)
	{
		lSliderX = GetLocationOnScreen().m_x + (int)((m_dimensions.m_width - m_sliderWidth) * ((m_currentValue - m_minValue) / (m_maxValue - m_minValue)));
		lSliderY = GetLocationOnScreen().m_y;
		lSliderWidth = m_sliderWidth;
		lSliderHeight = m_dimensions.m_height;

		lBarX = GetLocationOnScreen().m_x + (m_sliderWidth / 2);
		lBarY = GetLocationOnScreen().m_y + (m_dimensions.m_height / 2) - (m_barHeight / 2);
		lBarWidth = m_dimensions.m_width - m_sliderWidth;
		lBarHeight = m_barHeight;
	}
	else //if(m_eSliderDirection == ESliderDirection_Vertical)
	{
		lSliderX = GetLocationOnScreen().m_x;
		lSliderY = GetLocationOnScreen().m_y + (int)((m_dimensions.m_height - m_sliderWidth) * ((m_currentValue - m_minValue) / (m_maxValue - m_minValue)));
		lSliderWidth = m_dimensions.m_width;
		lSliderHeight = m_sliderWidth;

		lBarX = GetLocationOnScreen().m_x + (m_dimensions.m_width / 2) - (m_barHeight / 2);
		lBarY = GetLocationOnScreen().m_y + (m_sliderWidth / 2);
		lBarWidth = m_barHeight;
		lBarHeight = m_dimensions.m_height - m_sliderWidth;
	}

	int mouseX = lEvent.GetX();
	int mouseY = lEvent.GetY();

	// Check to see if we have clicked the slider to start dragging
	if((mouseX >= lSliderX) && (mouseX < lSliderX + lSliderWidth) && (mouseY >= lSliderY) && (mouseY < lSliderY + lSliderHeight))
	{
		if(m_bAllowDragging)
		{
			m_bDragging = true;
			m_bAllowDragginOutside = true;
		}
	}
	else
	{
		// Check to see if we have clicked on the bar to 'zoom' to a location
		if((mouseX >= lBarX) && (mouseX < lBarX + lBarWidth) && (mouseY >= lBarY) && (mouseY < lBarY + lBarHeight))
		{
			if(m_bAllowReleasingOnBar && !m_bDragging)
			{
				m_bPressedBar = true;
			}
		}
		else
		{
			// Don't allow releasing on the bar since we didnt first click on the bar, have to wait for release now
			m_bAllowReleasingOnBar = false;
		}

		// Don't allow dragging, or dragging outside, since our first press wasnt on the slider, have to wait for release now
		if(!m_bDragging)
		{
			m_bAllowDragging = false;
			m_bAllowDragginOutside = false;
		}
	}

	// If our parent is a GUIWindow, then makew this window have focus in the GUI, used to make it's depth the highest
	if(GetParent() != NULL && GetParent()->GetComponentType() == EComponentType_GUIWindow)
	{
		GUIWindow* lpParentWindow = (GUIWindow *)GetParent();
		lpParentWindow->SetFocusWindow();
	}

	OnMousePressed();
}
Beispiel #8
0
void Slider::MouseMotion(const MouseEvent& lEvent)
{
	int lSliderX;
	int lSliderY;
	int lSliderWidth;
	int lSliderHeight;

	int lBarX;
	int lBarY;
	int lBarWidth;
	int lBarHeight;

	if(m_eSliderDirection == ESliderDirection_Horizontal)
	{
		lSliderX = GetLocationOnScreen().m_x + (int)((m_dimensions.m_width - m_sliderWidth) * ((m_currentValue - m_minValue) / (m_maxValue - m_minValue)));
		lSliderY = GetLocationOnScreen().m_y;
		lSliderWidth = m_sliderWidth;
		lSliderHeight = m_dimensions.m_height;

		lBarX = GetLocationOnScreen().m_x + (m_sliderWidth / 2);
		lBarY = GetLocationOnScreen().m_y + (m_dimensions.m_height / 2) - (m_barHeight / 2);
		lBarWidth = m_dimensions.m_width - m_sliderWidth;
		lBarHeight = m_barHeight;
	}
	else //if(m_eSliderDirection == ESliderDirection_Vertical)
	{
		lSliderX = GetLocationOnScreen().m_x;
		lSliderY = GetLocationOnScreen().m_y + (int)((m_dimensions.m_height - m_sliderWidth) * ((m_currentValue - m_minValue) / (m_maxValue - m_minValue)));
		lSliderWidth = m_dimensions.m_width;
		lSliderHeight = m_sliderWidth;

		lBarX = GetLocationOnScreen().m_x + (m_dimensions.m_width / 2) - (m_barHeight / 2);
		lBarY = GetLocationOnScreen().m_y + (m_sliderWidth / 2);
		lBarWidth = m_barHeight;
		lBarHeight = m_dimensions.m_height - m_sliderWidth;
	}

	int mouseX = lEvent.GetX();
	int mouseY = lEvent.GetY();

	// Check to see if we are over the slider
	if((mouseX > lSliderX) && (mouseX < lSliderX + lSliderWidth) && (mouseY > lSliderY) && (mouseY < lSliderY + lSliderHeight))
	{
		if(!m_bPressedBar)
		{
			m_bHover = true;
		}
	}
	else
	{
		m_bHover = false;
	}

	// Check to see if we are over the bar
	if((mouseX >= lBarX) && (mouseX < lBarX + lBarWidth) && (mouseY >= lBarY) && (mouseY < lBarY + lBarHeight))
	{
		m_bOverBar = true;
	}
	else
	{
		m_bOverBar = false;
	}
}
Beispiel #9
0
void Slider::MouseDraggedOutside(const MouseEvent& lEvent)
{
	if(!m_bAllowDragginOutside)
	{
		// If we are not allowing dragging outside, just early out
		return;
	}

	if(!m_bFirstOutsideDrag)
	{
		m_lastX = lEvent.GetX();
		m_lastY = lEvent.GetY();
		m_bFirstOutsideDrag = true;
	}

	if(m_bDragginOutside)
	{
		int lNewX = lEvent.GetX();
		int lNewY = lEvent.GetY();

		int lMinX = GetLocationOnScreen().m_x;
		int lMinY = GetLocationOnScreen().m_y;
		int lMaxX = lMinX + m_dimensions.m_width;
		int lMaxY = lMinY + m_dimensions.m_height;

		int l_ChangeX = lNewX - m_lastX;
		int l_ChangeY = lNewY - m_lastY;

		if(l_ChangeX == 0 && l_ChangeY == 0)
			return;

		// Store the value before we change it, to see if we have actually changed the value
		float lValueBefore = m_currentValue;

		float lValueChange;
		if(m_eSliderDirection == ESliderDirection_Horizontal)
		{
			lValueChange = static_cast<float>(l_ChangeX) * ((m_maxValue - m_minValue) / (static_cast<float>(m_dimensions.m_width) - static_cast<float>(m_sliderWidth)));

			if( (lValueChange > 0) && (lNewX > lMinX))
			{
				m_currentValue += lValueChange;
			}
			else if((lValueChange < 0) && (lNewX < lMaxX))
			{
				m_currentValue += lValueChange;
			}
		}
		else //if(m_eSliderDirection == ESliderDirection_Vertical)
		{
			lValueChange = static_cast<float>(l_ChangeY) * ((m_maxValue - m_minValue) / (static_cast<float>(m_dimensions.m_height) - static_cast<float>(m_sliderWidth)));

			if( (lValueChange > 0) && (lNewY > lMinY))
			{
				m_currentValue += lValueChange;
			}
			else if((lValueChange < 0) && (lNewY < lMaxY))
			{
				m_currentValue += lValueChange;
			}
		}


		if(m_currentValue > m_maxValue)
		{
			m_currentValue = m_maxValue;
		}
		if(m_currentValue < m_minValue)
		{
			m_currentValue = m_minValue;
		}

		if(m_currentValue != lValueBefore)
		{
			ValueChanged();
		}

		m_lastX = lNewX;
		m_lastY = lNewY;
	}
}
Beispiel #10
0
void CSolidView::OnMouse( MouseEvent& event )
{
	if(event.LeftDown() || event.MiddleDown() || event.RightDown())
	{
		m_button_down_point = Point(event.GetX(), event.GetY());
		m_current_point = m_button_down_point;
		//StoreViewPoint();
		m_initial_point = m_button_down_point;
	}
	else if(event.Dragging())
	{
		Point point_diff = Point(event.GetX(), event.GetY()) - m_current_point;

		if(event.LeftIsDown())
		{
			if(point_diff.x > 100)point_diff.x = 100;
			else if(point_diff.x < -100)point_diff.x = -100;
			if(point_diff.y > 100)point_diff.y = 100;
			else if(point_diff.y < -100)point_diff.y = -100;
			double c=(m_size.x+m_size.y)/20;

			double ang_x = point_diff.x/c;
			double ang_y = point_diff.y/c;
			
			double f[3];
			for(int i = 0; i<3; i++)f[i] = m_target_point[i] - m_lens_point[i];
			double fl = sqrt(f[0]*f[0] + f[1]*f[1] + f[2]*f[2]);
			double uu[3];
			for(int i = 0; i<3; i++)uu[i] = m_vertical[i];

			double r[3];
			crossp(f, uu, r);
			norm(r);

			double sinangx = sin(ang_x);
			double oneminuscosangx = 1 - cos(ang_x);
			double sinangy = sin(ang_y);
			double oneminuscosangy = 1 - cos(ang_y);

			for(int i = 0; i<3; i++)
			{
				m_lens_point[i] = m_lens_point[i] - r[i] * sinangx*fl;
				m_lens_point[i] = m_lens_point[i] + f[i] * oneminuscosangx;
				f[i] = f[i] + r[i] * sinangx * fl;
				f[i] = f[i] - f[i] * oneminuscosangx;
			}

			crossp(f, uu, r);
			norm(r);

			for(int i = 0; i<3; i++)
			{
				m_lens_point[i] = m_lens_point[i] + uu[i] * sinangy*fl;
				m_lens_point[i] = m_lens_point[i] + f[i] * oneminuscosangy;
				m_vertical[i] = m_vertical[i] + f[i] * sinangy/fl;
				m_vertical[i] = m_vertical[i] - uu[i] * oneminuscosangy;	
			}
			LimitCamera();
		}
		else if(event.MiddleIsDown())
		{
			double f[3];
			for(int i = 0; i<3; i++)f[i] = m_target_point[i] - m_lens_point[i];
			norm(f);
			double r[3];
			crossp(f, m_vertical, r);

			double d = dist(m_target_point, m_lens_point);

			double div_x = (double)(point_diff.x) * d * 0.001;
			double div_y = (double)(point_diff.y) * d * 0.001;
			for(int i = 0; i<3; i++)m_target_point[i] = m_target_point[i] - r[i] * div_x + m_vertical[i] * div_y;
			for(int i = 0; i<3; i++)m_lens_point[i] = m_lens_point[i] - r[i] * div_x + m_vertical[i] * div_y;

			LimitCamera();
		}

		Refresh();
		m_current_point = Point(event.GetX(), event.GetY());
	}

	if(event.GetWheelRotation() != 0)
	{
		double wheel_value = (double)(event.GetWheelRotation());
		double multiplier = -wheel_value /1000.0;
		ViewScale(multiplier);
		Refresh();
	}
}