Пример #1
0
void Button::MouseReleased(const MouseEvent& lEvent)
{
	if(IsDisabled())
	{
		return;
	}

	SetSelected(false);

	OnMouseReleased();

	if(m_offsetApplied)
	{
		for(unsigned int i = 0; i < m_vpAddedComponentList.size(); i++)
		{
			if(m_bChangeLabelText)
			{
				if(m_vpAddedComponentList[i]->GetComponentType() == EComponentType_Label)
				{
					if(IsHover())
					{
						((Label*)m_vpAddedComponentList[i])->SetColour(m_hoverLabelColour);
					}
					else
					{
						((Label*)m_vpAddedComponentList[i])->SetColour(m_normalLabelColour);
					}
				
				}
			}

			m_vpAddedComponentList[i]->SetLocation(m_vpAddedComponentList[i]->GetLocation().m_x - m_pressedOffsetX, m_vpAddedComponentList[i]->GetLocation().m_y - m_pressedOffsetY);
		}
		m_label.SetLocation(m_label.GetLocation().m_x - m_pressedOffsetX, m_label.GetLocation().m_y - m_pressedOffsetY);
		if(m_bChangeLabelText)
		{
			if(IsHover())
			{
				m_label.SetColour(m_hoverLabelColour);
			}
			else
			{
				m_label.SetColour(m_normalLabelColour);
			}
		}

		m_offsetApplied = false;
	}


	if(m_Callback_Released)
	{
		m_Callback_Released(m_pCallbackData_Released);
	}
}
Пример #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();
}
Пример #3
0
bool CBaseControl::DispatchOwnEvent(sf::Event const & event)
{
	switch (event.type)
	{
	case sf::Event::MouseButtonPressed:
		return OnMousePressed(event.mouseButton);
	case sf::Event::MouseButtonReleased:
		return OnMouseReleased(event.mouseButton);
	case sf::Event::Resized:
		return OnWindowResized(event.size);
	case sf::Event::MouseMoved:
		return OnMouseMoved(event.mouseMove);
	default:
		return false;
	}
}
Пример #4
0
void InputEventController::ProcessInputEvent(const SDL_Event &evt)
{
	switch (evt.type) {
		case SDL_KEYDOWN: OnKeyPressed(evt.key); break;
		case SDL_KEYUP: OnKeyReleased(evt.key); break;
		case SDL_TEXTINPUT: OnTextInput(evt.text); break;

		case SDL_MOUSEMOTION: OnMouseMoved(evt.motion); break;
		case SDL_MOUSEBUTTONDOWN: OnMousePressed(evt.button); break;
		case SDL_MOUSEBUTTONUP: OnMouseReleased(evt.button); break;
		case SDL_MOUSEWHEEL: OnMouseWheel(evt.wheel); break;

		default:
			HR_LOG(info) << "Unhandled input event type: " << evt.type;
	}
}
Пример #5
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();
}
Пример #6
0
//---------------------------------------------------------------
// Purpose: 
//---------------------------------------------------------------
void CGuiClientElement::HandleMouseReleased( KeyCodes::KeyCode key, const Vector2f &absPos, const Vector2f &relPos )
{
	Vector2f rel = GetRelativePosition(relPos);
	OnMouseReleased(key, absPos, rel);
	CALL_FUNC_ON_CLIENT_CHILDREN( HandleMouseReleased, key, absPos, rel );
}
Пример #7
0
void TitleBar::MouseReleased(const MouseEvent& lEvent)
{
	m_bDragging = false;

	OnMouseReleased();
}
Пример #8
0
void Application::Run()
{
    //
    // keyboard
    //

    if (keyboard_needs_poll())
        poll_keyboard();

    for (int k = 0; k < 256; k++)
    {
        if (key[k])
        {
            OnKeyPress(k);

            if (!prevKeyState[k])
                OnKeyPressed(k);
        }
        else if (!key[k])
        {
            if (prevKeyState[k])
                OnKeyReleased(k);
        }
    }

    memcpy(prevKeyState,(char*)key,256);

    //
    // mouse
    //

    if (mouse_needs_poll())
        poll_mouse();

    for (int button = 0; button < (numMouseButtons); button++)
    {
        if ((mouse_b & (1 << button)) != 0)
        {
            mouseButtons[button] = true;
        }
        else
        {
            mouseButtons[button] = false;
        }

        if (mouseButtons[button] && (!prevMouseButtons[button]))
        {
            OnMousePressed(button, mouse_x, mouse_y);

            mousePressedLocs[button].x = mouse_x;
            mousePressedLocs[button].y = mouse_y;
        }
        else if ((!mouseButtons[button]) && prevMouseButtons[button])
        {
            OnMouseReleased(button, mouse_x, mouse_y);

            if ((mousePressedLocs[button].x == mouse_x) &&
                    (mousePressedLocs[button].y == mouse_y))
            {
                OnMouseClick(button,mouse_x,mouse_y);
            }
        }
    }

    memcpy(prevMouseButtons,mouseButtons,sizeof(bool)*(numMouseButtons+1));

    if ((mouse_x != prevMouseX) || (mouse_y != prevMouseY))
    {
        OnMouseMove(mouse_x,mouse_y);

        prevMouseX = mouse_x;
        prevMouseY = mouse_y;
    }

    // mouse wheel
    if (mouse_z > prevMouseZ)
    {
        OnMouseWheelUp( mouse_x, mouse_y );
        prevMouseZ = mouse_z;
    }
    else if (mouse_z < prevMouseZ)
    {
        OnMouseWheelDown( mouse_x, mouse_y );
        prevMouseZ = mouse_z;
    }

    //
    // run the game
    //

    show_mouse(NULL);
    RunGame();
    show_mouse(canvas);

    //
    // render canvas to the screen
    //

    blit(canvas,screen,0,0,0,0,screen->w,screen->h);

    //
    // sound polling (to ensure sounds currently playing will keep playing)
    //
    SoundOGG::PollSounds();

    //
    // handle timing
    //

    HandleTiming();
}