Exemplo n.º 1
0
void CommonAPI::ProcessPointerFrames(WPARAM wParam, POINTER_INFO pointerInfo, int index)
{
    if (interactionContexts[index]) // New frame
    {
        // Find out pointer count and frame history length
        UINT uEntriesCount = 0;
        UINT uPointerCount = 0;

        if (GetPointerFrameInfoHistory(GET_POINTERID_WPARAM(wParam), &uEntriesCount, &uPointerCount, NULL))
        {
            // Allocate space for pointer frame history
            POINTER_INFO *pPointerInfo = NULL;
            try
            {
                pPointerInfo = new POINTER_INFO [uEntriesCount * uPointerCount];
            }
            catch (...)
            {
                pPointerInfo = NULL;
            }

            if (pPointerInfo != NULL)
            {
                // Retrieve pointer frame history
                if (GetPointerFrameInfoHistory(GET_POINTERID_WPARAM(wParam), &uEntriesCount, &uPointerCount, pPointerInfo))
                {
                    // Process frame history
                    ProcessPointerFramesInteractionContext(interactionContexts[index], uEntriesCount, uPointerCount, pPointerInfo);
                }
                delete [] pPointerInfo;
                pPointerInfo = NULL;
            }
        }
    }
}
Exemplo n.º 2
0
bool dinput_handle_message(void *dinput, UINT message, WPARAM wParam, LPARAM lParam)
{
   struct dinput_input *di = (struct dinput_input *)dinput;
   /* WM_POINTERDOWN   : Arrives for each new touch event 
    *                    with a new ID - add to list.
    * WM_POINTERUP     : Arrives once the pointer is no 
    *                    longer down - remove from list.
    * WM_POINTERUPDATE : arrives for both pressed and 
    *                    hovering pointers - ignore hovering
   */

   switch (message)
   {
      case WM_POINTERDOWN:
      {
         struct pointer_status *new_pointer = 
            (struct pointer_status *)malloc(sizeof(struct pointer_status));

         if (!new_pointer)
         {
            RARCH_ERR("dinput_handle_message: pointer allocation in WM_POINTERDOWN failed.\n");
            return false;
         }

         new_pointer->pointer_id = GET_POINTERID_WPARAM(wParam);
         dinput_pointer_store_pos(new_pointer, lParam);
         dinput_add_pointer(di, new_pointer);
         return true;
      }
      case WM_POINTERUP:
      {
         int pointer_id = GET_POINTERID_WPARAM(wParam);
         dinput_delete_pointer(di, pointer_id);
         return true;
      }
      case WM_POINTERUPDATE:
      {
         int pointer_id = GET_POINTERID_WPARAM(wParam);
         struct pointer_status *pointer = dinput_find_pointer(di, pointer_id);
         if (pointer)
            dinput_pointer_store_pos(pointer, lParam);
         return true;
      }
      case WM_DEVICECHANGE:
      {
         if (di->joypad)
            di->joypad->destroy();
         di->joypad = input_joypad_init_driver(g_settings.input.joypad_driver);
         break;
      }
   }
   return false;
}
Exemplo n.º 3
0
bool BoidsSimulation::OnEvent( MSG* msg )
{
	switch (msg->message)
	{
	case WM_MOUSEWHEEL:
	{
		auto delta = GET_WHEEL_DELTA_WPARAM( msg->wParam );
		m_camera.ZoomRadius( -0.1f*delta );
	}
	case WM_POINTERDOWN:
	case WM_POINTERUPDATE:
	case WM_POINTERUP:
	{
		auto pointerId = GET_POINTERID_WPARAM( msg->wParam );
		POINTER_INFO pointerInfo;
		if (GetPointerInfo( pointerId, &pointerInfo )) {
			if (msg->message == WM_POINTERDOWN) {
				// Compute pointer position in render units
				POINT p = pointerInfo.ptPixelLocation;
				ScreenToClient( Core::g_hwnd, &p );
				RECT clientRect;
				GetClientRect( Core::g_hwnd, &clientRect );
				p.x = p.x * Core::g_config.swapChainDesc.Width / (clientRect.right - clientRect.left);
				p.y = p.y * Core::g_config.swapChainDesc.Height / (clientRect.bottom - clientRect.top);
				// Camera manipulation
				m_camera.AddPointer( pointerId );
			}
		}

		// Otherwise send it to the camera controls
		m_camera.ProcessPointerFrames( pointerId, &pointerInfo );
		if (msg->message == WM_POINTERUP) m_camera.RemovePointer( pointerId );
	}
	}
	return false;
}
// Processes messages for main Window
LRESULT CALLBACK WndProc(_In_ HWND hWnd, _In_ UINT msg, _In_ WPARAM wParam, _In_ LPARAM lParam)
{
    PAINTSTRUCT ps;

    switch (msg)
    {
    case WM_DESTROY:
        if (g_driver != nullptr)
        {
            delete g_driver;
            g_driver = nullptr;
        }

        PostQuitMessage(0);
        return 1;

    case WM_SIZE:
        g_width = LOWORD(lParam);
        g_height = HIWORD(lParam);
        break;

    case WM_PAINT:
        BeginPaint(hWnd, &ps);
        g_driver->RenderInitialState(g_width, g_height);
        EndPaint(hWnd, &ps);
        break;

    case WM_LBUTTONDOWN:
    case WM_LBUTTONUP:
    case WM_MOUSEMOVE:
        {
            if (msg == WM_MOUSEMOVE)
            {
                // Filter left button only
                if  (LOWORD(wParam) != MK_LBUTTON)
                {
                    break;
                }
            }

            // Create and process mouse event
            INPUT_EVENT inputEvent;
            inputEvent.pt.y = HIWORD(lParam);
            inputEvent.pt.x = LOWORD(lParam);
            inputEvent.eventSource = EVENT_SOURCE_MOUSE;
            inputEvent.eventType = (msg == WM_LBUTTONDOWN) ? EVENT_TYPE_DOWN :
                (msg == WM_MOUSEMOVE) ? EVENT_TYPE_MOVE : EVENT_TYPE_UP;
            inputEvent.cursorId = CURSOR_ID_MOUSE;
            g_driver->ProcessInputEvent(&inputEvent, 1);
        }
        break;

    case WM_TOUCHHITTESTING:
        // Do smart Touch hit testing
        return g_driver->OnTouchHitTesting((PTOUCH_HIT_TESTING_INPUT)lParam);

    case WM_POINTERDOWN:
    case WM_POINTERUPDATE:
    case WM_POINTERUP:
        {
            // Create and process pointer events
            INPUT_EVENT inputEvent;
            inputEvent.pt.y = HIWORD(lParam);
            inputEvent.pt.x = LOWORD(lParam);

            // Pointer position is in screen coordinates, convert to client coordinates
            ScreenToClient(hWnd, &inputEvent.pt);

            // Program works with any pointer input (touch, pen).
            // But only touch input can initialize smart Touch hit testing.
            inputEvent.eventSource = EVENT_SOURCE_POINTER;
            inputEvent.eventType = (msg == WM_POINTERDOWN) ? EVENT_TYPE_DOWN :
                (msg == WM_POINTERUPDATE) ? EVENT_TYPE_MOVE : EVENT_TYPE_UP;
            inputEvent.cursorId = GET_POINTERID_WPARAM(wParam);
            g_driver->ProcessInputEvent(&inputEvent, 1);
        }
        break;

    default:
        return DefWindowProc(hWnd, msg, wParam, lParam);
    }
    return 0;
}
Exemplo n.º 5
0
LRESULT Window::MsgProc(HWND hWnd, UINT uMsg, WPARAM wParam, LPARAM lParam)
{
    switch (uMsg)
    {
    case WM_ACTIVATE:
        active_ = (WA_INACTIVE != LOWORD(wParam));
        this->OnActive()(*this, active_);
        break;

    case WM_ERASEBKGND:
        return 1;

    case WM_PAINT:
        this->OnPaint()(*this);
        break;

    case WM_ENTERSIZEMOVE:
        // Previent rendering while moving / sizing
        ready_ = false;
        this->OnEnterSizeMove()(*this);
        break;

    case WM_EXITSIZEMOVE:
        this->OnExitSizeMove()(*this);
        ready_ = true;
        break;

    case WM_SIZE:
        // Check to see if we are losing or gaining our window.  Set the
        // active flag to match
        if ((SIZE_MAXHIDE == wParam) || (SIZE_MINIMIZED == wParam))
        {
            active_ = false;
            this->OnSize()(*this, false);
        }
        else
        {
            active_ = true;
            this->OnSize()(*this, true);
        }
        break;

    case WM_GETMINMAXINFO:
        // Prevent the window from going smaller than some minimu size
        reinterpret_cast<MINMAXINFO*>(lParam)->ptMinTrackSize.x = 100;
        reinterpret_cast<MINMAXINFO*>(lParam)->ptMinTrackSize.y = 100;
        break;

    case WM_SETCURSOR:
        this->OnSetCursor()(*this);
        break;

    case WM_CHAR:
        this->OnChar()(*this, static_cast<wchar_t>(wParam));
        break;

    case WM_INPUT:
        this->OnRawInput()(*this, reinterpret_cast<HRAWINPUT>(lParam));
        break;

#if (_WIN32_WINNT >= _WIN32_WINNT_WIN8)
    case WM_POINTERDOWN:
    {
        POINT pt = { GET_X_LPARAM(lParam), GET_Y_LPARAM(lParam) };
        ::ScreenToClient(this->HWnd(), &pt);
        this->OnPointerDown()(*this, int2(pt.x, pt.y), GET_POINTERID_WPARAM(wParam));
    }
    break;

    case WM_POINTERUP:
    {
        POINT pt = { GET_X_LPARAM(lParam), GET_Y_LPARAM(lParam) };
        ::ScreenToClient(this->HWnd(), &pt);
        this->OnPointerUp()(*this, int2(pt.x, pt.y), GET_POINTERID_WPARAM(wParam));
    }
    break;

    case WM_POINTERUPDATE:
    {
        POINT pt = { GET_X_LPARAM(lParam), GET_Y_LPARAM(lParam) };
        ::ScreenToClient(this->HWnd(), &pt);
        this->OnPointerUpdate()(*this, int2(pt.x, pt.y), GET_POINTERID_WPARAM(wParam),
                                IS_POINTER_INCONTACT_WPARAM(wParam));
    }
    break;

    case WM_POINTERWHEEL:
    {
        POINT pt = { GET_X_LPARAM(lParam), GET_Y_LPARAM(lParam) };
        ::ScreenToClient(this->HWnd(), &pt);
        this->OnPointerWheel()(*this, int2(pt.x, pt.y), GET_POINTERID_WPARAM(wParam),
                               GET_WHEEL_DELTA_WPARAM(wParam));
    }
    break;

#elif (_WIN32_WINNT >= _WIN32_WINNT_WIN7)
    case WM_TOUCH:
        this->OnTouch()(*this, reinterpret_cast<HTOUCHINPUT>(lParam), LOWORD(wParam));
        break;
#endif

    case WM_CLOSE:
        this->OnClose()(*this);
        active_ = false;
        ready_ = false;
        closed_ = true;
        ::PostQuitMessage(0);
        return 0;
    }

    return default_wnd_proc_(hWnd, uMsg, wParam, lParam);
}
Exemplo n.º 6
0
// Event handler
LRESULT CALLBACK MyWndProc(HWND hWnd, UINT message, WPARAM wParam, LPARAM lParam)
{
    gpRenderer->HandleEvent(message, wParam, lParam);

    switch (message)
    {
    case WM_CLOSE:
        gShouldClose = true;
        return 0;
    case WM_SIZE: {
        UINT ww = LOWORD(lParam);
        UINT wh = HIWORD(lParam);

        // Ignore resizing to minimized
        if (ww == 0 || wh == 0) return 0;

        gWindowWidth = (int)ww;
        gWindowHeight = (int)wh;
        gRenderWidth = (UINT)(double(gWindowWidth)  * gRenderScale);
        gRenderHeight = (UINT)(double(gWindowHeight) * gRenderScale);

        // Update camera projection
        float aspect = (float)gRenderWidth / (float)gRenderHeight;
        gCamera.Projection(DirectX::XM_PIDIV2 * 0.8f * 3 / 2, aspect);
        
        ResizeApp(gWindowWidth, gWindowHeight);

        return 0;
    }
    case WM_MOUSEWHEEL: {
        auto delta = GET_WHEEL_DELTA_WPARAM(wParam);
        gCamera.ZoomRadius(-0.07f * delta);
        return 0;
    }
    case WM_POINTERDOWN:
    case WM_POINTERUPDATE:
    case WM_POINTERUP: {
        auto pointerId = GET_POINTERID_WPARAM(wParam);
        POINTER_INFO pointerInfo;
        if (GetPointerInfo(pointerId, &pointerInfo)) {
            if (message == WM_POINTERDOWN) {
                
                // Compute pointer position in render units
                POINT p = pointerInfo.ptPixelLocation;
                ScreenToClient(hWnd, &p);
                
                RECT clientRect;
                GetClientRect(hWnd, &clientRect);
                p.x = p.x * gRenderWidth / (clientRect.right - clientRect.left);
                p.y = p.y * gRenderHeight / (clientRect.bottom - clientRect.top);

                gCamera.AddPointer(pointerId);
            }

            // Otherwise send it to the camera controls
            gCamera.ProcessPointerFrames(pointerId, &pointerInfo);
            if (message == WM_POINTERUP) gCamera.RemovePointer(pointerId);
        }
        return 0;
    }
    default:
        return DefWindowProc(hWnd, message, wParam, lParam);
    }
}
Exemplo n.º 7
0
bool dinput_handle_message(void *dinput, UINT message, WPARAM wParam, LPARAM lParam)
{
   struct dinput_input *di = (struct dinput_input *)dinput;
   settings_t *settings    = config_get_ptr();
   /* WM_POINTERDOWN   : Arrives for each new touch event
    *                    with a new ID - add to list.
    * WM_POINTERUP     : Arrives once the pointer is no
    *                    longer down - remove from list.
    * WM_POINTERUPDATE : arrives for both pressed and
    *                    hovering pointers - ignore hovering
   */

   switch (message)
   {
      case WM_MOUSEMOVE:
         di->window_pos_x = GET_X_LPARAM(lParam);
         di->window_pos_y = GET_Y_LPARAM(lParam);
         break;
      case WM_POINTERDOWN:
         {
            struct pointer_status *new_pointer =
               (struct pointer_status *)malloc(sizeof(struct pointer_status));

            if (!new_pointer)
            {
               RARCH_ERR("dinput_handle_message: pointer allocation in WM_POINTERDOWN failed.\n");
               return false;
            }

            new_pointer->pointer_id = GET_POINTERID_WPARAM(wParam);
            dinput_pointer_store_pos(new_pointer, lParam);
            dinput_add_pointer(di, new_pointer);
            return true;
         }
      case WM_POINTERUP:
         {
            int pointer_id = GET_POINTERID_WPARAM(wParam);
            dinput_delete_pointer(di, pointer_id);
            return true;
         }
      case WM_POINTERUPDATE:
         {
            int pointer_id = GET_POINTERID_WPARAM(wParam);
            struct pointer_status *pointer = dinput_find_pointer(di, pointer_id);
            if (pointer)
               dinput_pointer_store_pos(pointer, lParam);
            return true;
         }
      case WM_DEVICECHANGE:
            if (di->joypad)
               di->joypad->destroy();
            di->joypad = input_joypad_init_driver(settings->input.joypad_driver, di);
         break;
      case WM_MOUSEWHEEL:
            if (((short) HIWORD(wParam))/120 > 0)
               di->mouse_wu = true;
            if (((short) HIWORD(wParam))/120 < 0)
               di->mouse_wd = true;
         break;
      case WM_MOUSEHWHEEL:
         {
            if (((short) HIWORD(wParam))/120 > 0)
               di->mouse_hwu = true;
            if (((short) HIWORD(wParam))/120 < 0)
               di->mouse_hwd = true;
         }
         break;
   }

   return false;
}
Exemplo n.º 8
0
LRESULT CALLBACK DeskBandWindow::WndProc(HWND hWnd, UINT uMessage, WPARAM wParam, LPARAM lParam)
{
	LRESULT lResult = 0;
	DeskBandWindow *pDeskBand = (DeskBandWindow*)pBandWin;
	TRACKMOUSEEVENT tme;
	if (uMessage == Shell)
	{
		switch (wParam)
		{
		case HSHELL_WINDOWREPLACED:
			if (pDeskBand->mShow && ((HWND)lParam == pIcon->mIconHwnd))
				BringWindowToTop(pIcon->mIconHwnd);
			break;
		case HSHELL_RUDEAPPACTIVATED:
		case HSHELL_WINDOWACTIVATED:
			if ((HWND)lParam == pIcon->mIconHwnd)
				break;
			if (pConfig != nullptr)
				pConfig->Update((HWND)lParam);
			break;
		}
	}
	switch (uMessage)
	{

	case WM_MOUSEMOVE:
	    tme.cbSize = sizeof(TRACKMOUSEEVENT);
	    tme.dwFlags = TME_LEAVE;
	    tme.hwndTrack = pDeskBand->mHwnd;
	    tme.dwHoverTime = 0;
	    ::TrackMouseEvent(&tme);

		if (pDeskBand->Mouse == Left)
		{
			pDeskBand->Mouse = Entered;
			InvalidateRect(pDeskBand->mHwnd, NULL, true);
			UpdateWindow(pDeskBand->mHwnd);
		}
	    break;

	case WM_LBUTTONDOWN:
		if (pDeskBand->Mouse == Entered)
		{
			pDeskBand->Mouse = ClickDown;
			InvalidateRect(pDeskBand->mHwnd, NULL, true);
			UpdateWindow(pDeskBand->mHwnd);
		}
		break;

	case WM_LBUTTONUP:
		if (pDeskBand->Mouse == ClickDown)
		{
			pDeskBand->Mouse = Entered;
			InvalidateRect(pDeskBand->mHwnd, NULL, true);
			UpdateWindow(pDeskBand->mHwnd);
			pDeskBand->mIconWin.Show(pDeskBand->mShow = !pDeskBand->mShow);
			pDeskBand->mTouchDetector.Set(pDeskBand->mShow);
			if (pDeskBand->mShow)
			{
				pConfig->mEventMode = (pConfig->mEventMode == Configuration::EEventMouse) ? Configuration::EEventNormal : Configuration::EEventMouse; // only for testing
				pConfig->Refresh();
				pConfig->UpdateEvents();
			}		
		}
		break;

	case WM_MOUSELEAVE:
		if (pDeskBand->Mouse != Left)
		{
			pDeskBand->Mouse = Left;
			InvalidateRect(pDeskBand->mHwnd, NULL, true);
			UpdateWindow(pDeskBand->mHwnd);
		}
		break;

	case WM_PAINT:
		pDeskBand->OnPaint(NULL);
		break;

	case WM_PRINTCLIENT:
		pDeskBand->OnPaint(reinterpret_cast<HDC>(wParam));
		break;

	case WM_ERASEBKGND:
		if (pDeskBand->m_fCompositionEnabled)
		{
			lResult = 1;
		}
		break;
	case USER_F_CHANGE:
		if (pConfig != nullptr)
			pConfig->Update((HWND)wParam);
		break;
	case USER_DOWN:
	{
					  Point Location = { (int)GET_X_LPARAM(lParam), (int)GET_Y_LPARAM(lParam) };
					  pTouch->Update(GET_POINTERID_WPARAM(wParam), ETouchDown, Location);
					  break;
	}
	case USER_UP:
	{
					  Point Location = { (int)GET_X_LPARAM(lParam), (int)GET_Y_LPARAM(lParam) };
					  pTouch->Update(GET_POINTERID_WPARAM(wParam), ETouchUp, Location);
					  break;
	}
	case USER_MOVE:
	{
					  Point Location = { (int)GET_X_LPARAM(lParam), (int)GET_Y_LPARAM(lParam) };
					  pTouch->Update(GET_POINTERID_WPARAM(wParam), ETouchMove, Location);
					  break;
	}
	}

	if (uMessage != WM_ERASEBKGND)
	{
		lResult = DefWindowProc(hWnd, uMessage, wParam, lParam);
	}

	return lResult;
};
Exemplo n.º 9
0
LRESULT CALLBACK WindowProcSubclass(HWND hWnd, UINT message, WPARAM wParam, LPARAM lParam, UINT_PTR uIdSubclass, DWORD_PTR dwRefData)
{
	CommonAPI* api = CommonAPI::getInstance();
	POINTER_INFO pointerInfo = {};
	HRESULT hr;
    switch (message)
    {
	case WM_POINTERDOWN:
        // Get frame id from current message
        if (GetPointerInfo(GET_POINTERID_WPARAM(wParam), &pointerInfo))
        {
			asIScriptFunction* sf = api->module->GetFunctionByDecl("int OnPointerDown(int x, int y)");
			if(sf == 0)
				FILE_LOG(logERROR) << "The script must have the function 'OnPointerDown'.";

			asIScriptContext* ctx = api->engine->CreateContext();
			ctx->Prepare(sf);
			ctx->SetArgDWord(0, pointerInfo.ptPixelLocation.x);
			ctx->SetArgDWord(1, pointerInfo.ptPixelLocation.y);
			ctx->Execute();
			int meow = ctx->GetReturnQWord();

			if(meow >= 0 && sf != 0)
			{
				// Background was hit
				hr = AddPointerInteractionContext(api->interactionContexts[meow], GET_POINTERID_WPARAM(wParam));
				if (SUCCEEDED(hr))
				{
					api->pointers[meow].push_back(GET_POINTERID_WPARAM(wParam));
					api->ProcessPointerFrames(wParam, pointerInfo, meow);
				}
			}
        }
        break;

    case WM_POINTERUPDATE:
        // Get frame id from current message
        if (GetPointerInfo(GET_POINTERID_WPARAM(wParam), &pointerInfo))
        {
            // Background
            if (api->IsPointerInteraction(GET_POINTERID_WPARAM(wParam)))
			{
                api->ProcessPointerFrames(wParam, pointerInfo, 0);
			}
        }
        break;

    case WM_POINTERUP:
        // Get frame id from current message
        if (GetPointerInfo(GET_POINTERID_WPARAM(wParam), &pointerInfo))
        {
            // Background
			int t = api->IsPointerInteraction(GET_POINTERID_WPARAM(wParam));
            if (t >= 0)
            {
                api->ProcessPointerFrames(wParam, pointerInfo, t);
                hr = RemovePointerInteractionContext(api->interactionContexts[t],
                                                     GET_POINTERID_WPARAM(wParam));

				asIScriptFunction* sf = api->module->GetFunctionByDecl("void OnPointerUp(int)");
				if(sf == 0)
					FILE_LOG(logERROR) << "The script must have the function 'OnPointerUp'.";

				asIScriptContext* ctx = api->engine->CreateContext();
				ctx->Prepare(sf);
				ctx->SetArgDWord(0, t);
				ctx->Execute();

                if (SUCCEEDED(hr))
                {
					if (!api->pointers[t].empty())
						api->pointers[t].remove(GET_POINTERID_WPARAM(wParam));
                }
            }
        }

        break;
    default:
        return DefSubclassProc(hWnd, message, wParam, lParam);
    }
    return DefSubclassProc(hWnd, message, wParam, lParam);
}