YSTest  PreAlpha_b500_20140530
The YSLib Test Project
 全部  命名空间 文件 函数 变量 类型定义 枚举 枚举值 友元 宏定义  
InputManager.cpp
浏览该文件的文档.
1 /*
2  © 2012-2014 FrankHB.
3 
4  This file is part of the YSLib project, and may only be used,
5  modified, and distributed under the terms of the YSLib project
6  license, LICENSE.TXT. By continuing to use, modify, or distribute
7  this file you indicate that you have read the license and
8  understand and accept it fully.
9 */
10 
28 #include "Helper/YModules.h"
29 #include YFM_Helper_InputManager
30 #include YFM_YCLib_Input
31 #include YFM_Helper_Host
32 #include YFM_Helper_HostRenderer // for Host::Window, Host::RenderWindow;
33 #include YFM_Helper_GUIApplication // for FetchEnvironment;
34 
35 namespace YSLib
36 {
37 
38 using namespace UI;
39 
40 namespace Devices
41 {
42 
43 InputManager::InputManager()
44  : GUI_state(FetchGUIState()), cursor_state()
46  , env(Host::FetchEnvironment())
47 #endif
48 {}
49 
50 #if YCL_DS
51 # define YCL_CURSOR_VALID
52 #elif YF_Hosted
53 # define YCL_CURSOR_VALID if(cursor_state != Point::Invalid)
54 #else
55 # error "Unsupported platform found."
56 #endif
57 void
59 {
60  auto& st(GUI_state.get());
61  const auto disp([&](const KeyInput& keyset, VisualEvent key_evt,
62  VisualEvent touch_evt){
63  if(keyset[KeyCodes::Primary] || keyset[KeyCodes::Secondary]
64  || keyset[KeyCodes::Tertiary])
65  {
66  YCL_CURSOR_VALID
67  {
68  CursorEventArgs e(wgt, keyset, cursor_state);
69 
70  st.ResponseCursor(e, touch_evt);
71  }
72  }
73  else if(keyset.any())
74  {
75  KeyEventArgs e(wgt, keyset);
76 
77  st.ResponseKey(e, key_evt);
78  }
79  });
81 
82  disp(keys, KeyUp, TouchUp);
83 #if YF_Hosted
84  YCL_CURSOR_VALID
85  {
86  CursorEventArgs e(wgt, keys, cursor_state);
87 
88  st.ResponseCursor(e, CursorOver);
89  }
90 #endif
92  disp(keys, KeyDown, TouchDown);
94  disp(keys, KeyHeld, TouchHeld);
95 #if YCL_Win32
96  const UI::WheelDelta raw_mouse(env.get().RawMouseButton);
97 
98  if(raw_mouse != 0)
99  {
100  CursorWheelEventArgs e(wgt, raw_mouse, keys, cursor_state);
101 
102  st.ResponseCursor(e, CursorWheel);
103  env.get().RawMouseButton = 0;
104  }
105 #endif
106 }
107 
108 IWidget*
110 {
111 #if YF_Hosted
112  const auto p_wnd(env.get().GetForegroundWindow());
113 
114  if(!p_wnd)
115  return {};
116 
117 #endif
118  using namespace platform::KeyCodes;
119 
120  // FIXME: [DS] crashing after sleeping(default behavior of closing then
121  // reopening lid) on real machine due to LibNDS default interrupt
122  // handler for power management.
123 // platform::AllowSleep(true);
125 
126 #if YCL_DS
127  if(platform_ex::FetchKeyState()[Touch])
128 #endif
129  {
130 #if YCL_DS
131  cursor_state = platform_ex::FetchCursor();
132 #elif YCL_Win32
133  ::POINT cursor;
134 
135  ::GetCursorPos(&cursor);
136  ::ScreenToClient(p_wnd->GetNativeHandle(), &cursor);
137 
138  const auto& pr(p_wnd->GetInputBounds());
139 
140  if(YB_LIKELY(pr.first.X != pr.second.X && pr.first.Y != pr.second.Y)
141  && (!p_wnd->BoundsLimited
142  || (IsInInterval<::LONG>(cursor.x, pr.first.X, pr.second.X)
143  && IsInInterval<::LONG>(cursor.y, pr.first.Y, pr.second.Y))))
144  yunseq(cursor_state.X = cursor.x - pr.first.X,
145  cursor_state.Y = cursor.y - pr.first.Y);
146  else
148 #endif
149  }
150 #if YF_Hosted
151  if(const auto p_render_wnd = dynamic_cast<Host::RenderWindow*>(p_wnd))
152  return &p_render_wnd->GetRenderer().GetWidgetRef();
153 #endif
154  return {};
155 }
156 #undef YCL_CURSOR_VALID
157 
158 } // namespace Devices;
159 
160 } // namespace YSLib;
161 
YF_API const platform::KeyInput & FetchKeyState()
取按键状态。
Definition: Input.cpp:123
YF_API GUIState & FetchGUIState()
取默认图形用户界面公共状态。
Definition: ygui.cpp:442
void DispatchInput(UI::IWidget &)
向指定部件分发响应输入状态。
#define YF_Hosted
宿主环境。
Definition: Platform.h:138
按键输入事件参数类。
Definition: ywgtevt.h:167
std::reference_wrapper< UI::GUIState > GUI_state
Definition: InputManager.h:49
static const GBinaryGroup Invalid
无效(不在屏幕坐标系中)对象。
Definition: ygdibase.h:57
Drawing::Point cursor_state
指针设备光标位置。
Definition: InputManager.h:54
#define yunseq
无序列依赖表达式组求值。
Definition: ydef.h:748
_tWidget & wgt
Definition: ywgtevt.h:596
UI::IWidget * Update()
更新输入状态。
滚轮事件参数。
Definition: ywgtevt.h:217
if(YB_LIKELY(!error)) if(YB_LIKELY(!(error
YF_API platform::KeyInput FetchKeyUpState()
取键释放状态。
Definition: Input.cpp:147
ptrdiff_t WheelDelta
滚轮度量:以角度计量的转动滚轮的幅度。
Definition: ywgtevt.h:210
YF_API platform::KeyInput FetchKeyDownState()
取键按下状态。
Definition: Input.cpp:139
#define YB_LIKELY(expr)
Definition: ydef.h:297
YF_API void UpdateKeyStates()
更新按键状态。
Definition: Input.cpp:169
指针设备输入事件参数类。
Definition: ywgtevt.h:183
std::bitset< KeyBitsetWidth > KeyInput
按键并行位宽。
Definition: Keys.h:68