Beispiel #1
0
GEM_EXTERN void dispatchGemWindowMessages(WindowInfo &win)
{
  SDL_Event event;
  while (SDL_PollEvent(&event))
  {
    switch (event.type)
    {
      case SDL_QUIT:
        // ignore
        break;
      case SDL_WINDOWEVENT:
        switch (event.window.event)
        {
          case SDL_WINDOWEVENT_CLOSE:
            // ignore
            break;
          case SDL_WINDOWEVENT_RESIZED:
          case SDL_WINDOWEVENT_SIZE_CHANGED:
            triggerResizeEvent(event.window.data1, event.window.data2);
            break;
        }
        break;
      case SDL_KEYDOWN:
      case SDL_KEYUP:
        triggerKeyboardEvent
          ( key2symbol(event.key.keysym.sym).c_str()
          , event.key.keysym.scancode
          , event.type == SDL_KEYDOWN
          );
        break;
      case SDL_MOUSEBUTTONDOWN:
      case SDL_MOUSEBUTTONUP:
        triggerButtonEvent
          ( event.button.button == SDL_BUTTON_LEFT ? 0
          : event.button.button == SDL_BUTTON_MIDDLE ? 1
          : event.button.button == SDL_BUTTON_RIGHT ? 2
          : event.button.button // FIXME
          , event.type == SDL_MOUSEBUTTONDOWN
          , event.button.x
          , event.button.y
          );
        break;
      case SDL_MOUSEMOTION:
        triggerMotionEvent(event.motion.x, event.motion.y);
        break;
      case SDL_MOUSEWHEEL: // FIXME
        if (event.wheel.y != 0) triggerWheelEvent(0, event.wheel.y);
        if (event.wheel.x != 0) triggerWheelEvent(1, event.wheel.x);
        break;
    }
  }
}
Beispiel #2
0
/////////////////////////////////////////////////////////
// MainWndProc
//
/////////////////////////////////////////////////////////
LONG WINAPI MainWndProc (HWND hWnd, UINT uMsg, WPARAM wParam, LPARAM lParam)
{
	static RECT rcClient;
	static int ctrlKeyDown = 0;

	// assume that we handle the message
    long lRet = 0;

    switch (uMsg)
    {
        // mouse motion
        case WM_MOUSEMOVE:
            triggerMotionEvent(LOWORD(lParam), HIWORD(lParam));
            break;

        // left button up
        case WM_LBUTTONUP:
            triggerButtonEvent(0, 0, LOWORD(lParam), HIWORD(lParam));
            break;

        // left button down
        case WM_LBUTTONDOWN:
            triggerButtonEvent(0, 1, LOWORD(lParam), HIWORD(lParam));
            break;

        // middle button up
        case WM_MBUTTONUP:
            triggerButtonEvent(1, 0, LOWORD(lParam), HIWORD(lParam));
            break;

        // middle button down
        case WM_MBUTTONDOWN:
            triggerButtonEvent(1, 1, LOWORD(lParam), HIWORD(lParam));
            break;

        // right button up
        case WM_RBUTTONUP:
            triggerButtonEvent(2, 0, LOWORD(lParam), HIWORD(lParam));
            break;

        // right button down
        case WM_RBUTTONDOWN:
            triggerButtonEvent(2, 1, LOWORD(lParam), HIWORD(lParam));
            break;
        // keyboard action
        case WM_KEYUP:
			if ((int)wParam == VK_CONTROL)
				ctrlKeyDown = 0;

            triggerKeyboardEvent((char*)&wParam, (int)wParam, 1);
            break;

            // keyboard action
    case WM_KEYDOWN:
			if ((int)wParam == VK_CONTROL)
				ctrlKeyDown = 1;
			else if (ctrlKeyDown && (int)wParam == 'R')
        gemAbortRendering();
			else
				triggerKeyboardEvent((char*)&wParam, (int)wParam, 0);
      break;

      // resize event
    case WM_SIZE:
      triggerResizeEvent(LOWORD(lParam), HIWORD(lParam));
      GetClientRect(hWnd, &rcClient);
      break;

      // we want to override these messages
      // and not do anything
    case WM_DESTROY:
    case WM_CLOSE:
      break;
    case WM_CREATE:
      {
      }
      break;

      // pass all unhandled messages to DefWindowProc
    default:
      lRet = DefWindowProc (hWnd, uMsg, wParam, lParam);
      break;
    }
    return(lRet);
}