Exemplo n.º 1
0
void InputState::updateKey(UINT msg, WPARAM wParam, LPARAM lParam)
{
    switch(msg)
    {
        case WM_KEYDOWN:
            if( !(lParam & bit30Mask) )
            {
                KeyboardStateNow[wParam] = true;
                //DebugPrintf("KeyNum: %d ; KeyState:%s \n", (unsigned int)wParam, "true");
            }
            break;
        case WM_KEYUP:
                KeyboardStateNow[wParam] = false;
                //DebugPrintf("KeyNum: %d ; KeyState:%s \n", (unsigned int)wParam, "false" );
            break;
        case WM_LBUTTONDOWN:
            MouseStateNow[Left] = true;
            break;
        case WM_RBUTTONDOWN:
            MouseStateNow[Right] = true;
            break;

        case WM_LBUTTONUP:
            MouseStateNow[Left] = false;
            break;
        case WM_RBUTTONUP:
            MouseStateNow[Right] = false;
            break;
        case WM_MOUSEMOVE:
            UpdateMousePos(lParam);
            break;
    }
}
Exemplo n.º 2
0
void App::PassiveMouseCB(int x, int y)
{
	UpdateMousePos(x, y);

	if (!m_pGame->HandlePassiveMouse(x, y))
	{

	}
}
Exemplo n.º 3
0
void App::MovingMouseCB(int x, int y)
{
	UpdateMousePos(x, y);

	if (!m_pGame->HandleMovingMouse(x,y))
	{

	}
}
Exemplo n.º 4
0
void App::MouseCB(int button, int state, int x, int y)
{
	UpdateMousePos(x, y);

	if (!m_pGame->HandleMouse(button, state, x, y))
	{

	}
}
Exemplo n.º 5
0
void World::OnMouseMove(int nX, int nY)
{
    // Although this works, the recast in ogWindowProc is a better solution.
//    if(nX > 32768) nX -= 65536;
//    if(nY > 32768) nY -= 65536;

//    printf("OnMouseMove: %d, %d\n", nX, nY);
//    fflush(stdout);

    UpdateMousePos(nX, nY);

    // lets try this - nope
    // RefreshPickPosition();

    // Need to change this so it calls the callback during either render or update
    // so that the mouse pick position is up to date

    stringstream ss;
    ss << "OnMouseMove(" << m_vMouse2DPositionDelta.x << "," << m_vMouse2DPositionDelta.y << "," << nX << "," << nY << ")";
    luaCall(ss.str());

    if(m_bMouseMovesCamera)
    {
        if(m_bRightMouseDown)
        {
            if(glutGetModifiers() & GLUT_ACTIVE_SHIFT)
            {
                float fStepSize = m_vMouse2DPositionDelta.y * 0.2;

                mlVector3D vCamera = GetCameraTransform()->GetTranslation();
                float fDistance = (m_vMousePickPosition - vCamera).Magnitude();
                fStepSize *= fDistance * 0.05f;

                fStepSize = mlClamp(fStepSize, -20.0f, 20.0f);

                mlVector3D vForward = vCamera - m_vMousePickPosition;
                vForward.Normalise();
                vForward *= fStepSize;

                m_trnCamera.ApplyTranslation(vForward);
            }
            else
            {
                PanCamera(m_vMouse2DPositionDelta.x, m_vMouse2DPositionDelta.y);
            }
        }

        if(m_bLeftMouseDown)
        {
            // This is a magic number which maps pixels of mouse motion to radians of rotation
            float fRotationSpeed = 0.008f;

            float fHeadingChange = fRotationSpeed * m_vMouse2DPositionDelta.x;
            float fPitchChange   = fRotationSpeed * m_vMouse2DPositionDelta.y;

            if(m_bDoubleClick)
            {
                if(m_bUsePositionPreservingOrbitCamera)
                    PositionPreservingOrbitCamera(m_vMousePickPosition, fHeadingChange * 0.5, fPitchChange * 0.5);
                else
                    OrientationPreservingOrbitCamera(m_vMousePickPosition, fHeadingChange * 0.5, fPitchChange * 0.5);
            }
            else
            {
                RotateCamera(fHeadingChange, fPitchChange);
            }
        }
    }
}
Exemplo n.º 6
0
Arquivo: main.c Projeto: Jasu/HashTWM
int WINAPI WinMain(HINSTANCE hInstance, HINSTANCE hPrevInstance, LPSTR lpCmdLine, int nShowCmd)
{
  WNDCLASSEX winClass;
  HWND hwnd;
  MSG msg;

  // Process command line
  LPWSTR *argv = NULL;
  int argc;
  int i;
  unsigned short tilingMode;

  argv = CommandLineToArgvW(GetCommandLineW(), &argc);

  for (i = 0; i < argc; i++) {
    char arg[128];
    wsprintfA(arg, "%S", argv[i]);

    if (i < (argc - 1)) {
      char nextarg[128];
      wsprintfA(nextarg, "%S", argv[i + 1]);

      if (!strcmp(arg, "-o")) {
        alpha = atoi(nextarg);
      } else if (!strcmp(arg, "-i")) {
        if (ignoreCount < MAX_IGNORE) {
          sprintf(ignoreClasses[ignoreCount++], "%s", nextarg);
        }
      } else if (!strcmp(arg, "-a")) {
        include_mode = 1; // Include mode instead of exclude

        if (includeCount < MAX_IGNORE) {
          sprintf(includeClasses[includeCount++], "%s", nextarg);
        }
      } else if (!strcmp(arg, "-m")) {
        int y;
        modkeys = 0;

        for (y = 0; y < strlen(nextarg); y++) {
          switch (nextarg[y])
          {
            case 'c':
              modkeys |= MOD_CONTROL;
              break;
            case 'a':
              modkeys |= MOD_ALT;
              break;
            case 's':
              modkeys |= MOD_SHIFT;
              break;
            case 'w':
              modkeys |= MOD_WIN;
              break;
          }
        }
      } else if (!strcmp(arg, "-t")) {
        tilingMode = atoi(nextarg);
      } else if (!strcmp(arg, "-left")) {
        screen_x = atoi(nextarg);
      } else if (!strcmp(arg, "-top")) {
        screen_y = atoi(nextarg);
      } else if (!strcmp(arg, "-width")) {
        screen_width = atoi(nextarg);
      } else if (!strcmp(arg, "-height")) {
        screen_height = atoi(nextarg);
      }
    }
    if (!strcmp(arg, "-v")) {
      MessageBox(NULL, VERSION, "Version", MB_OK);
      LocalFree(argv);
      return 1;
    } else if (!strcmp(arg, "-l")) {
      lockMouse = 1;
    } else if (!strcmp(arg, "-x")) {
      experimental_mouse = 1;
    } else if (!strcmp(arg, "--one-tag")) {
      one_tag_per_window = 1;
    }
  }

  // Initialize tags
  for (i = 0; i < TAGS; i++) {
    tags[i].nodes = NULL;
    tags[i].last_node = NULL;
    tags[i].current_window = NULL;
    tags[i].tilingMode = DEFAULT_TILING_MODE;
    tags[i].masterarea_count = 1;
  }

  LocalFree(argv);

  winClass.cbSize = sizeof(WNDCLASSEX);
  winClass.style = 0;
  winClass.lpfnWndProc = WndProc;
  winClass.cbClsExtra = 0;
  winClass.cbWndExtra = 0;
  winClass.hInstance = hInstance;
  winClass.hIcon = NULL;
  winClass.hIconSm = NULL;
  winClass.hCursor = NULL;
  winClass.hbrBackground = NULL;
  winClass.lpszMenuName = NULL;
  winClass.lpszClassName = NAME;

  if (!RegisterClassEx(&winClass)) {
    MessageBox(NULL, "Error Registering Window Class", "Error", MB_OK | MB_ICONERROR);
    return 0; // Bail
  }

  hwnd = CreateWindowEx(0, NAME, NAME, 0, 0, 0, 0, 0, HWND_MESSAGE, NULL, hInstance, NULL);

  if (!hwnd) {
    MessageBox(NULL, "Error Creating Window", "Error", MB_OK | MB_ICONERROR);
    return 0; // Bail
  }

  if (!screen_x && !screen_y && !screen_width && !screen_height) { // Screen options aren't being specified from the command line so set some defaults
    RECT workarea;
    SystemParametersInfo(SPI_GETWORKAREA, 0, &workarea, 0);
    screen_x = workarea.left;
    screen_y = workarea.top;
    screen_width = workarea.right - workarea.left;
    screen_height = workarea.bottom - workarea.top;
  }

  RegisterHotkeys(hwnd);
  UpdateMousePos(hwnd);

  EnumWindows(EnumWindowsRestore, 0); // Restore windows on startup so they get tiled
  EnumWindows(EnumWindowsProc, 0);

  ArrangeWindows();

  // Get function pointer for RegisterShellHookWindow
  if ( RegisterShellHookWindow_ == NULL )
  {
    RegisterShellHookWindow_ = (BOOL (__stdcall *)(HWND))GetProcAddress(GetModuleHandle("USER32.DLL"), "RegisterShellHookWindow");
    if (RegisterShellHookWindow_ == NULL) {
      MessageBox(NULL, "Could not find RegisterShellHookWindow", "Error", MB_OK | MB_ICONERROR);
      return 0;
    }
  }

  RegisterShellHookWindow_(hwnd);
  shellhookid = RegisterWindowMessage("SHELLHOOK"); // Grab a dynamic id for the SHELLHOOK message to be used later

  while (GetMessage(&msg, NULL, 0, 0) > 0)
  {
    TranslateMessage(&msg);
    DispatchMessage(&msg);
  }

  return msg.wParam;
}
Exemplo n.º 7
0
Arquivo: main.c Projeto: Jasu/HashTWM
LRESULT CALLBACK WndProc(HWND hwnd, UINT msg, WPARAM wParam, LPARAM lParam)
{
  node *current = NULL;
  node *nodes;
  unsigned short tag;

  switch (msg)
  {
    case WM_CREATE:
      if (experimental_mouse) {
        SetTimer(hwnd, TIMER_UPDATE_MOUSE, 500, NULL); // Poll for mouse position
      }
      break;

    case WM_CLOSE:
      {
        ClipCursor(0); // Release Cursor Lock
        DeregisterShellHookWindow(hwnd);
        UnregisterHotkeys(hwnd);
        if (experimental_mouse) {
          KillTimer(hwnd, TIMER_UPDATE_MOUSE); // Mouse Poll Timer
        }
        for (tag=0; tag<TAGS; tag++) {
          nodes = tags[tag].nodes;
          for (current = nodes; current;) {
            node *next = current->next;
            RestoreWindow(current->hwnd);
            RemoveNode(current->hwnd, tag);
            current = next;
          }
          DestroyWindow(hwnd);
        }
      }
      break;

    case WM_DESTROY:
      PostQuitMessage(WM_QUIT);
      break;

    case WM_HOTKEY:
      if (wParam >= KEY_TOGGLE_T1 && wParam < (KEY_TOGGLE_T1 + TAGS)) {
        ToggleTag(wParam - KEY_TOGGLE_T1);
        break;
      } else if (wParam >= KEY_SWITCH_T1 && wParam < (KEY_SWITCH_T1 + TAGS)) {
        MinimizeTag(current_tag);
        current_tag = wParam - KEY_SWITCH_T1;
        ArrangeWindows();
        break;
      }

      current = tags[current_tag].current_window;

      switch (wParam)
      {
        case KEY_SELECT_UP:
          if (current) {
            tags[current_tag].current_window = GetNextNode();
            FocusCurrent();
          }
          break;

        case KEY_SELECT_DOWN:
          if (current) {
            tags[current_tag].current_window = GetPreviousNode();
            FocusCurrent();
          }
          break;

        case KEY_MOVE_MAIN:
          SwapWindowWithNode(tags[current_tag].nodes);
          ArrangeWindows();
          break;

        case KEY_EXIT:
          PostMessage(hwnd, WM_CLOSE, 0, 0);
          break;

        case KEY_MARGIN_LEFT:
          margin -= 20;
          ArrangeWindows();
          break;

        case KEY_MARGIN_RIGHT:
          margin += 20;
          ArrangeWindows();
          break;

        case KEY_IGNORE:
          if (!disableNext) {
            disableNext = 1;
          } else {
            disableNext = 0;
          }
          break;

        case KEY_MOUSE_LOCK:
          if (lockMouse) {
            lockMouse = 0;
            ClipCursor(0);
          } else {
            lockMouse = 1;
            FocusCurrent();
          }
          break;

        case KEY_TILING_MODE:
          tags[current_tag].tilingMode = (tags[current_tag].tilingMode + 1) % 3;
          ArrangeWindows();
          break;

        case KEY_MOVE_UP:
          if (current) {
            SwapWindowWithNode(GetNextNode());
            ArrangeWindows();
          }
          break;

        case KEY_MOVE_DOWN:
          if (current) {
            SwapWindowWithNode(GetPreviousNode());
            ArrangeWindows();
          }
          break;

        case KEY_DISP_CLASS:
          {
            LPSTR temp = (LPSTR)malloc(sizeof(TCHAR) * 128);
            GetClassName(GetForegroundWindow(), temp, 128);
            MessageBox(NULL, temp, "Window Class", MB_OK);
            free(temp);
          }
          break;

        case KEY_TILE:
          if (IsGoodWindow(GetForegroundWindow())) {
            AddNode(GetForegroundWindow(), current_tag);
            ArrangeWindows();
          }
          break;

        case KEY_UNTILE:
          FullRemoveNode(GetForegroundWindow());
          ArrangeWindows();
          break;

        case KEY_INC_AREA:
          tags[current_tag].masterarea_count++;
          ArrangeWindows();
          break;

        case KEY_DEC_AREA:
          tags[current_tag].masterarea_count--;
          ArrangeWindows();
          break;

        case KEY_CLOSE_WIN:
          PostMessage(GetForegroundWindow(), WM_CLOSE, 0, 0);
          break;
      }
      break;

    case WM_TIMER:
      switch (wParam)
      {
        case TIMER_UPDATE_MOUSE:
          UpdateMousePos(hwnd);
          break;
      }
      break;

    default:
      if (msg == shellhookid) { // Handle the Shell Hook message
        switch (wParam)
        {
          case HSHELL_WINDOWCREATED:
            if (IsGoodWindow((HWND)lParam)) {
              AddNode((HWND)lParam, current_tag);
              ArrangeWindows();
              FocusCurrent();
            }
            break;

          case HSHELL_WINDOWDESTROYED:
            FullRemoveNode((HWND)lParam);
            ArrangeWindows();
            FocusCurrent();
            break;

          case HSHELL_WINDOWACTIVATED:
            {
              node *found = FindNode((HWND)lParam, current_tag);
              if (found) {
                tags[current_tag].current_window = current = found;
                FocusCurrent();
              }
            }
            break;
        }
      } else {
        return DefWindowProc(hwnd, msg, wParam, lParam);
      }
  }
  return 0;
}