void HookGui::HGInputController::ProcessInputCommands(HGWidget* _mainWidget, HGInputDispatcher& _inputDispatcher)
{
	// Lets start processing the input
	_inputDispatcher.StartIterator();
	
	// Until our iterator is valid
	while (_inputDispatcher.IteratorIsValid())
	{
		// Get the input
		HGInputCommand input = _inputDispatcher.GetIteratorInput();

		// If we used this input
		bool inputConsumed = false;

		// Get the input type
		switch (input.inputAuthor)
		{
			case HGInputAuthor::System:
			{
				break;
			}

			case HGInputAuthor::Mouse:
			{
				// Process the mouse input from the main widget
				if (ProcessMouseInput(_mainWidget, input))
				{
					// Set that we used the input
					inputConsumed = true;
				}

				break;
			}

			case HGInputAuthor::Keyboard:
			{
				break;
			}
		}

		// If we used the input, remove if from the dispatcher
		if (inputConsumed || true)
		{
			// Remove it
			_inputDispatcher.ConsumeIteratorInput();
		}
	}
}
bool HookGui::HGInputController::ProcessMouseInput(HGWidget* _currentWidget, HGInputCommand& _input)
{
	// Get the input location
	uint32_t x = _input.upperParam;
	uint32_t y = _input.lowerParam;

	// Check if the mouse input was inside this widget area
	if (!_currentWidget->PointIsInside(x, y))
	{
		return false;
	}

	// Check if we can interact or if we are hidden
	if (!_currentWidget->CanInteract() || _currentWidget->IsHidden())
	{
		return false;
	}

	// Check if any of this widget child can receive this input
	const std::vector<HGWidget*>& childArray = _currentWidget->GetChildArray();
	for (int i = 0; i < childArray.size(); i++)
	{
		// Check if this child uses this input
		if (ProcessMouseInput(childArray[i], _input))
		{
			return true;
		}
	}

	// Ok if we are here, the input is ours //

	// Check if this widget can receive inputs
	if (!_currentWidget->CanReceiveInput())
	{
		return false;
	}

	// Process the input for this widget
	if (!_currentWidget->EvaluateInput(_input))
	{
		return false;
	}

	return true;
}
예제 #3
0
LRESULT CALLBACK WindowProc(HWND hWnd, UINT msg, WPARAM wParam, LPARAM lParam)
{
    switch (msg)
    {
    //======================================================================================
    case WM_KEYDOWN:
    {
        keys[wParam] = TRUE;					// If So, Mark It As TRUE
        return 0;								// Jump Back
    }
    break;
    case WM_KEYUP:								// Has A Key Been Released?
    {
        keys[wParam] = FALSE;					// If So, Mark It As FALSE
        return 0;								// Jump Back
    }
    break;
    //======================================================================================

    case WM_ACTIVATE:
        switch (wParam)
        {
        default:
            break;

        case WA_ACTIVE:
        case WA_CLICKACTIVE:
            g_hasFocus = true;
            break;

        case WA_INACTIVE:
            if (g_isFullScreen)
                ShowWindow(hWnd, SW_MINIMIZE);
            g_hasFocus = false;
            break;
        }
        break;

    case WM_CHAR:
        switch (static_cast<int>(wParam))
        {
        case VK_ESCAPE:
            PostMessage(hWnd, WM_CLOSE, 0, 0);
            break;



        default:
            break;
        }
        break;

    case WM_DESTROY:
        PostQuitMessage(0);
        return 0;

    case WM_SIZE:
        g_windowWidth = static_cast<int>(LOWORD(lParam));
        g_windowHeight = static_cast<int>(HIWORD(lParam));
        break;

    case WM_SYSKEYDOWN:
        if (wParam == VK_RETURN)
            ToggleFullScreen();
        break;

    default:
        ProcessMouseInput(hWnd, msg, wParam, lParam);
        break;
    }

    return DefWindowProc(hWnd, msg, wParam, lParam);
}