TouchPanelEmulator.cpp 2.0 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970
  1. #include "TouchPanelEmulator.h"
  2. #include <iostream>
  3. #include <tchar.h>
  4. #include <tpcshrd.h>
  5. #include "../ComponentsManager.h"
  6. #include "../../Constants.h"
  7. #include "../../framework.h"
  8. #include "../../Input/Mouse/Mouse.h"
  9. #include "../../Input/Keyboard/Keyboard.h"
  10. using namespace TLAC::Input;
  11. namespace TLAC::Components
  12. {
  13. TouchPanelEmulator::TouchPanelEmulator()
  14. {
  15. }
  16. TouchPanelEmulator::~TouchPanelEmulator()
  17. {
  18. }
  19. const char* TouchPanelEmulator::GetDisplayName()
  20. {
  21. return "touch_panel_emulator";
  22. }
  23. void TouchPanelEmulator::Initialize(ComponentsManager* manager)
  24. {
  25. componentsManager = manager;
  26. state = GetTouchStatePtr((void*)TASK_TOUCH_ADDRESS);
  27. // Make touches on actual touchscreens more responsive
  28. const DWORD_PTR dwHwndTabletProperty =
  29. TABLET_DISABLE_PRESSANDHOLD | // disables press and hold (right-click) gesture
  30. TABLET_DISABLE_PENTAPFEEDBACK | // disables UI feedback on pen up (waves)
  31. TABLET_DISABLE_PENBARRELFEEDBACK | // disables UI feedback on pen button down (circle)
  32. TABLET_DISABLE_FLICKS; // disables pen flicks (back, forward, drag down, drag up)
  33. SetProp(TLAC::framework::DivaWindowHandle, MICROSOFT_TABLETPENSERVICE_PROPERTY, reinterpret_cast<HANDLE>(dwHwndTabletProperty));
  34. }
  35. void TouchPanelEmulator::Update()
  36. {
  37. state->ConnectionState = 1;
  38. }
  39. void TouchPanelEmulator::UpdateInput()
  40. {
  41. if (!componentsManager->GetUpdateGameInput() || componentsManager->IsDwGuiActive() || componentsManager->IsDwGuiHovered())
  42. return;
  43. // TODO: rescale TouchReaction aet position
  44. auto keyboard = Keyboard::GetInstance();
  45. auto pos = Mouse::GetInstance()->GetRelativePosition();
  46. state->XPosition = (float)pos.x;
  47. state->YPosition = (float)pos.y;
  48. bool down = keyboard->IsDown(VK_LBUTTON);
  49. bool released = keyboard->IsReleased(VK_LBUTTON);
  50. state->ContactType = (down ? 0x2 : released ? 0x1 : 0x0);
  51. state->Pressure = (float)(state->ContactType != 0);
  52. }
  53. TouchPanelState* TouchPanelEmulator::GetTouchStatePtr(void *address)
  54. {
  55. return (TouchPanelState*)address;
  56. }
  57. }