• R/O
  • HTTP
  • SSH
  • HTTPS

コミット

タグ
未設定

よく使われているワード(クリックで追加)

javaandroidc++linuxc#objective-ccocoa誰得qtrubybathyscaphegamephpguicwindows翻訳pythonomegattwitterframeworkbtronarduinovb.net計画中(planning stage)directxpreviewertestゲームエンジンdom

Simple C++ UI framework and more...


コミットメタ情報

リビジョン9454a9948f639f1c00acad68583c43bffbe49bff (tree)
日時2018-06-02 23:31:38
作者Starg <starg@user...>
コミッターStarg

ログメッセージ

Fix pointer events

変更サマリ

差分

--- a/include/sirius/widget.hpp
+++ b/include/sirius/widget.hpp
@@ -8,6 +8,7 @@
88 #include <chrono>
99 #include <future>
1010 #include <memory>
11+#include <optional>
1112 #include <string>
1213 #include <string_view>
1314 #include <variant>
@@ -40,8 +41,33 @@ enum class MouseButtonKind
4041 Middle
4142 };
4243
44+struct MouseButtonState
45+{
46+ MouseButtonState() : Primary(false), Secondary(false), Middle(false)
47+ {
48+ }
49+
50+ MouseButtonState(bool primary, bool secondary, bool middle) : Primary(primary), Secondary(secondary), Middle(middle)
51+ {
52+ }
53+
54+ // left
55+ bool Primary : 1;
56+ // right
57+ bool Secondary : 1;
58+ bool Middle : 1;
59+};
60+
4361 struct ModifierKeyState
4462 {
63+ ModifierKeyState() : Alt(false), Ctrl(false), Shift(false)
64+ {
65+ }
66+
67+ ModifierKeyState(bool alt, bool ctrl, bool shift) : Alt(alt), Ctrl(ctrl), Shift(shift)
68+ {
69+ }
70+
4571 bool Alt : 1;
4672 bool Ctrl : 1;
4773 bool Shift : 1;
@@ -194,30 +220,32 @@ struct ChildWidgetEventArgs : EventArgs
194220 struct PointerEventArgs : EventArgs
195221 {
196222 PointerKind Kind = PointerKind::Unknown;
197- std::variant<std::monostate, MouseButtonKind, std::intptr_t> ID;
223+ std::variant<std::monostate, MouseButtonKind, MouseButtonState, std::intptr_t> What;
198224 Vec2<float> Position;
225+ std::uint32_t RepeatCount = 0;
199226 float Pressure = 1.0f;
200227 Vec2<float> Tilt;
201- ModifierKeyState ModifierKeys{};
228+ ModifierKeyState ModifierKeys;
202229 };
203230
204231 struct WheelEventArgs : EventArgs
205232 {
206233 Vec2<float> Position;
207234 Vec2<float> Delta;
208- ModifierKeyState ModifierKeys{};
235+ ModifierKeyState ModifierKeys;
209236 };
210237
211238 struct KeyEventArgs : EventArgs
212239 {
213240 std::variant<SpecialKey, char32_t> Key = U'\0';
214- ModifierKeyState ModifierKeys{};
241+ std::uint32_t RepeatCount = 0;
242+ ModifierKeyState ModifierKeys;
215243 };
216244
217245 struct TextEventArgs : EventArgs
218246 {
219247 std::string Text;
220- ModifierKeyState ModifierKeys{};
248+ ModifierKeyState ModifierKeys;
221249 };
222250
223251 } // namespace WidgetEvent
@@ -390,15 +418,9 @@ public:
390418 // pt is in root coordinates
391419 void InvokePointerDown(
392420 PointerKind kind,
393- std::variant<std::monostate, MouseButtonKind, std::intptr_t> id,
394- Vec2<float> pt,
395- ModifierKeyState modifierKeyState
396- );
397-
398- void InvokePointerDown(
399- PointerKind kind,
400- std::variant<std::monostate, MouseButtonKind, std::intptr_t> id,
421+ std::variant<std::monostate, MouseButtonKind, std::intptr_t> what,
401422 Vec2<float> pt,
423+ std::uint32_t repeatCount,
402424 float pressure,
403425 Vec2<float> tilt,
404426 ModifierKeyState modifierKeyState
@@ -406,14 +428,7 @@ public:
406428
407429 void InvokePointerUp(
408430 PointerKind kind,
409- std::variant<std::monostate, MouseButtonKind, std::intptr_t> id,
410- Vec2<float> pt,
411- ModifierKeyState modifierKeyState
412- );
413-
414- void InvokePointerUp(
415- PointerKind kind,
416- std::variant<std::monostate, MouseButtonKind, std::intptr_t> id,
431+ std::variant<std::monostate, MouseButtonKind, std::intptr_t> what,
417432 Vec2<float> pt,
418433 float pressure,
419434 Vec2<float> tilt,
@@ -422,14 +437,7 @@ public:
422437
423438 void InvokePointerMove(
424439 PointerKind kind,
425- std::variant<std::monostate, MouseButtonKind, std::intptr_t> id,
426- Vec2<float> pt,
427- ModifierKeyState modifierKeyState
428- );
429-
430- void InvokePointerMove(
431- PointerKind kind,
432- std::variant<std::monostate, MouseButtonKind, std::intptr_t> id,
440+ std::variant<std::monostate, MouseButtonState, std::intptr_t> what,
433441 Vec2<float> pt,
434442 float pressure,
435443 Vec2<float> tilt,
@@ -437,8 +445,8 @@ public:
437445 );
438446
439447 void InvokeWheel(Vec2<float> pt, Vec2<float> delta, ModifierKeyState modifierKeyState);
440- void InvokeKeyDown(SpecialKey key, ModifierKeyState modifierKeyState);
441- void InvokeKeyDown(char32_t key, ModifierKeyState modifierKeyState);
448+ void InvokeKeyDown(SpecialKey key, std::uint32_t repeatCount, ModifierKeyState modifierKeyState);
449+ void InvokeKeyDown(char32_t key, std::uint32_t repeatCount, ModifierKeyState modifierKeyState);
442450 void InvokeKeyUp(SpecialKey key, ModifierKeyState modifierKeyState);
443451 void InvokeKeyUp(char32_t key, ModifierKeyState modifierKeyState);
444452 void InvokeText(std::string_view text, ModifierKeyState modifierKeyState);
--- a/src/widget.cpp
+++ b/src/widget.cpp
@@ -162,7 +162,6 @@ bool Widget::SetFocus()
162162 return false;
163163 }
164164
165- auto pWThis = weak_from_this();
166165 auto pOldFocus = GetUIManager().GetFocusedWidget().lock();
167166
168167 if (pOldFocus)
@@ -171,7 +170,7 @@ bool Widget::SetFocus()
171170 }
172171
173172 InvokeEvent(WidgetEvent::GotFocus);
174- GetUIManager().SetFocusedWidget(pWThis);
173+ GetUIManager().SetFocusedWidget(weak_from_this());
175174 return true;
176175 }
177176
@@ -269,18 +268,9 @@ void Widget::OnRender(Renderer&)
269268
270269 void Widget::InvokePointerDown(
271270 PointerKind kind,
272- std::variant<std::monostate, MouseButtonKind, std::intptr_t> id,
273- Vec2<float> pt,
274- ModifierKeyState modifierKeyState
275-)
276-{
277- InvokePointerDown(kind, id, pt, 1.0f, {}, modifierKeyState);
278-}
279-
280-void Widget::InvokePointerDown(
281- PointerKind kind,
282- std::variant<std::monostate, MouseButtonKind, std::intptr_t> id,
271+ std::variant<std::monostate, MouseButtonKind, std::intptr_t> what,
283272 Vec2<float> pt,
273+ std::uint32_t repeatCount,
284274 float pressure,
285275 Vec2<float> tilt,
286276 ModifierKeyState modifierKeyState
@@ -291,8 +281,9 @@ void Widget::InvokePointerDown(
291281 // pWidget->SetCapture();
292282 WidgetEvent::PointerEventArgs args;
293283 args.Kind = kind;
294- args.ID = id;
284+ std::visit([&args] (auto&& x) { args.What = std::forward<decltype(x)>(x); }, what);
295285 args.Position = pt;
286+ args.RepeatCount = repeatCount;
296287 args.Pressure = pressure;
297288 args.Tilt = tilt;
298289 args.ModifierKeys = modifierKeyState;
@@ -303,17 +294,7 @@ void Widget::InvokePointerDown(
303294
304295 void Widget::InvokePointerUp(
305296 PointerKind kind,
306- std::variant<std::monostate, MouseButtonKind, std::intptr_t> id,
307- Vec2<float> pt,
308- ModifierKeyState modifierKeyState
309-)
310-{
311- InvokePointerUp(kind, id, pt, 1.0f, {}, modifierKeyState);
312-}
313-
314-void Widget::InvokePointerUp(
315- PointerKind kind,
316- std::variant<std::monostate, MouseButtonKind, std::intptr_t> id,
297+ std::variant<std::monostate, MouseButtonKind, std::intptr_t> what,
317298 Vec2<float> pt,
318299 float pressure,
319300 Vec2<float> tilt,
@@ -325,7 +306,7 @@ void Widget::InvokePointerUp(
325306 // pWidget->ReleaseCapture();
326307 WidgetEvent::PointerEventArgs args;
327308 args.Kind = kind;
328- args.ID = id;
309+ std::visit([&args] (auto&& x) { args.What = std::forward<decltype(x)>(x); }, what);
329310 args.Position = pt;
330311 args.Pressure = pressure;
331312 args.Tilt = tilt;
@@ -337,17 +318,7 @@ void Widget::InvokePointerUp(
337318
338319 void Widget::InvokePointerMove(
339320 PointerKind kind,
340- std::variant<std::monostate, MouseButtonKind, std::intptr_t> id,
341- Vec2<float> pt,
342- ModifierKeyState modifierKeyState
343-)
344-{
345- InvokePointerMove(kind, id, pt, 1.0f, {}, modifierKeyState);
346-}
347-
348-void Widget::InvokePointerMove(
349- PointerKind kind,
350- std::variant<std::monostate, MouseButtonKind, std::intptr_t> id,
321+ std::variant<std::monostate, MouseButtonState, std::intptr_t> what,
351322 Vec2<float> pt,
352323 float pressure,
353324 Vec2<float> tilt,
@@ -358,7 +329,7 @@ void Widget::InvokePointerMove(
358329 {
359330 WidgetEvent::PointerEventArgs args;
360331 args.Kind = kind;
361- args.ID = id;
332+ std::visit([&args] (auto&& x) { args.What = std::forward<decltype(x)>(x); }, what);
362333 args.Position = pt;
363334 args.Pressure = pressure;
364335 args.Tilt = tilt;
@@ -381,24 +352,26 @@ void Widget::InvokeWheel(Vec2<float> pt, Vec2<float> delta, ModifierKeyState mod
381352 }
382353 }
383354
384-void Widget::InvokeKeyDown(SpecialKey key, ModifierKeyState modifierKeyState)
355+void Widget::InvokeKeyDown(SpecialKey key, std::uint32_t repeatCount, ModifierKeyState modifierKeyState)
385356 {
386357 if (auto pWidget = FindKeyTarget())
387358 {
388359 WidgetEvent::KeyEventArgs args;
389360 args.Key = key;
361+ args.RepeatCount = repeatCount;
390362 args.ModifierKeys = modifierKeyState;
391363
392364 pWidget->InvokeEvent(WidgetEvent::KeyDown, args);
393365 }
394366 }
395367
396-void Widget::InvokeKeyDown(char32_t key, ModifierKeyState modifierKeyState)
368+void Widget::InvokeKeyDown(char32_t key, std::uint32_t repeatCount, ModifierKeyState modifierKeyState)
397369 {
398370 if (auto pWidget = FindKeyTarget())
399371 {
400372 WidgetEvent::KeyEventArgs args;
401373 args.Key = key;
374+ args.RepeatCount = repeatCount;
402375 args.ModifierKeys = modifierKeyState;
403376
404377 pWidget->InvokeEvent(WidgetEvent::KeyDown, args);