当前位置: 首页>>代码示例>>C++>>正文


C++ MyWindow::inputCallback方法代码示例

本文整理汇总了C++中MyWindow::inputCallback方法的典型用法代码示例。如果您正苦于以下问题:C++ MyWindow::inputCallback方法的具体用法?C++ MyWindow::inputCallback怎么用?C++ MyWindow::inputCallback使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在MyWindow的用法示例。


在下文中一共展示了MyWindow::inputCallback方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。

示例1: WndProc

LRESULT CALLBACK MyWindow::WndProc(HWND hWnd,UINT message,WPARAM wParam,LPARAM lParam) {
  MyWindow *window = (MyWindow*)GetWindowLong(hWnd,GWL_USERDATA);
  if(message==WM_INPUT) {
    UINT dwSize = 40;
    static BYTE lpb[40];
    GetRawInputData((HRAWINPUT)lParam,RID_INPUT,lpb,&dwSize,sizeof(RAWINPUTHEADER));
    RAWINPUT* raw = (RAWINPUT*)lpb;

    if(raw->header.dwType == RIM_TYPEMOUSE) {
      if(raw->data.mouse.usButtonFlags & RI_MOUSE_LEFT_BUTTON_DOWN) {
        bool alreadyDown=window->inputCodeDown.find(VK_LBUTTON)==window->inputCodeDown.end();
        window->inputCodeDown.insert(VK_LBUTTON);

        if(window->inputCallback) {
          window->inputCallback(VK_LBUTTON,alreadyDown?inputDown:inputPress);
        }
      } else if(raw->data.mouse.usButtonFlags & RI_MOUSE_LEFT_BUTTON_UP) {
        window->inputCodeDown.erase(VK_LBUTTON);

        if(window->inputCallback) {
          window->inputCallback(VK_LBUTTON,inputUp);
        }
      } else if(raw->data.mouse.usButtonFlags & RI_MOUSE_MIDDLE_BUTTON_DOWN) {
        bool alreadyDown=window->inputCodeDown.find(VK_MBUTTON)==window->inputCodeDown.end();
        window->inputCodeDown.insert(VK_MBUTTON);

        if(window->inputCallback) {
          window->inputCallback(VK_MBUTTON,alreadyDown?inputDown:inputPress);
        }
      } else if(raw->data.mouse.usButtonFlags & RI_MOUSE_MIDDLE_BUTTON_UP) {
        window->inputCodeDown.erase(VK_MBUTTON);

        if(window->inputCallback) {
          window->inputCallback(VK_MBUTTON,inputUp);
        }
      } else if(raw->data.mouse.usButtonFlags & RI_MOUSE_RIGHT_BUTTON_DOWN) {
        bool alreadyDown=window->inputCodeDown.find(VK_RBUTTON)==window->inputCodeDown.end();
        window->inputCodeDown.insert(VK_RBUTTON);

        if(window->inputCallback) {
          window->inputCallback(VK_RBUTTON,alreadyDown?inputDown:inputPress);
        }
      } else if(raw->data.mouse.usButtonFlags & RI_MOUSE_RIGHT_BUTTON_UP) {
        window->inputCodeDown.erase(VK_RBUTTON);

        if(window->inputCallback) {
          window->inputCallback(VK_RBUTTON,inputUp);
        }
      } else if(raw->data.mouse.usButtonFlags & RI_MOUSE_BUTTON_1_DOWN) {
      } else if(raw->data.mouse.usButtonFlags & RI_MOUSE_BUTTON_1_UP) {
      } else if(raw->data.mouse.usButtonFlags & RI_MOUSE_BUTTON_2_DOWN) {
      } else if(raw->data.mouse.usButtonFlags & RI_MOUSE_BUTTON_2_UP) {
      } else if(raw->data.mouse.usButtonFlags & RI_MOUSE_BUTTON_3_DOWN) {
      } else if(raw->data.mouse.usButtonFlags & RI_MOUSE_BUTTON_3_UP) {
      } else if(raw->data.mouse.usButtonFlags & RI_MOUSE_BUTTON_4_DOWN) {
      } else if(raw->data.mouse.usButtonFlags & RI_MOUSE_BUTTON_4_UP) {
      } else if(raw->data.mouse.usButtonFlags & RI_MOUSE_BUTTON_5_DOWN) {
      } else if(raw->data.mouse.usButtonFlags & RI_MOUSE_BUTTON_5_UP) {
      } else if(raw->data.mouse.usButtonFlags & RI_MOUSE_WHEEL) {
        int z=raw->data.mouse.usButtonData;
      } else {
        int x = raw->data.mouse.lLastX;
        int y = raw->data.mouse.lLastY;

        if(window->mouseMoveCallback && window->isFocused()) {
          window->mouseMoveCallback(x,y);
        }
      }
    } else if(raw->header.dwType == RIM_TYPEKEYBOARD) {
      USHORT key=raw->data.keyboard.VKey;
      bool up=raw->data.keyboard.Flags & RI_KEY_BREAK;

      //std::cout << key << " " << up << std::endl;
      //InputCode code=inputUndefined;

      //auto it=window->inputCodeMap.find(key);

      //if(it!=window->inputCodeMap.end()) {
      //  code=it->second;
      //}

      if(!up) {
        bool alreadyDown=window->inputCodeDown.find(key)!=window->inputCodeDown.end();
        window->inputCodeDown.insert(key);

        if(window->inputCallback && window->isFocused()) {
          window->inputCallback(key,alreadyDown?inputDown:inputPress);
        }
      } else{

        window->inputCodeDown.erase(key);
        if(window->inputCallback && window->isFocused()) {
          window->inputCallback(key,inputUp);
        }
      }
    }
  } else if(message==WM_DESTROY) {
    PostQuitMessage(0);
  } else if(message==WM_SIZE) {
    window->clientWidth=LOWORD(lParam);
//.........这里部分代码省略.........
开发者ID:archer1357,项目名称:Deferred-Renderer,代码行数:101,代码来源:Window.cpp


注:本文中的MyWindow::inputCallback方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。