зеркало из https://github.com/AvaloniaUI/angle.git
OSWindow: add optional debugging of events received
BUG=angleproject:830 Change-Id: Icd854ee152f15ec1de4293b5ed2ed49cb1a5fc2b Reviewed-on: https://chromium-review.googlesource.com/270451 Reviewed-by: Jamie Madill <jmadill@chromium.org> Reviewed-by: Geoff Lang <geofflang@chromium.org> Tested-by: Corentin Wallez <cwallez@chromium.org>
This commit is contained in:
Родитель
0d3afab874
Коммит
938f1ca341
|
@ -6,6 +6,101 @@
|
|||
|
||||
#include "OSWindow.h"
|
||||
|
||||
#include <iostream>
|
||||
|
||||
#include "common/debug.h"
|
||||
|
||||
#ifndef DEBUG_EVENTS
|
||||
#define DEBUG_EVENTS 0
|
||||
#endif
|
||||
|
||||
#if DEBUG_EVENTS
|
||||
static const char *MouseButtonName(MouseButton button)
|
||||
{
|
||||
switch (button)
|
||||
{
|
||||
case MOUSEBUTTON_UNKNOWN:
|
||||
return "Unknown";
|
||||
case MOUSEBUTTON_LEFT:
|
||||
return "Left";
|
||||
case MOUSEBUTTON_RIGHT:
|
||||
return "Right";
|
||||
case MOUSEBUTTON_MIDDLE:
|
||||
return "Middle";
|
||||
case MOUSEBUTTON_BUTTON4:
|
||||
return "Button4";
|
||||
case MOUSEBUTTON_BUTTON5:
|
||||
return "Button5";
|
||||
default:
|
||||
UNREACHABLE();
|
||||
return nullptr;
|
||||
}
|
||||
}
|
||||
|
||||
static void PrintEvent(const Event& event)
|
||||
{
|
||||
switch (event.Type)
|
||||
{
|
||||
case Event::EVENT_CLOSED:
|
||||
std::cout << "Event: Window Closed" << std::endl;
|
||||
break;
|
||||
case Event::EVENT_MOVED:
|
||||
std::cout << "Event: Window Moved (" << event.Move.X
|
||||
<< ", " << event.Move.Y << ")" << std::endl;
|
||||
break;
|
||||
case Event::EVENT_RESIZED:
|
||||
std::cout << "Event: Window Resized (" << event.Size.Width
|
||||
<< ", " << event.Size.Height << ")" << std::endl;
|
||||
break;
|
||||
case Event::EVENT_LOST_FOCUS:
|
||||
std::cout << "Event: Window Lost Focus" << std::endl;
|
||||
break;
|
||||
case Event::EVENT_GAINED_FOCUS:
|
||||
std::cout << "Event: Window Gained Focus" << std::endl;
|
||||
break;
|
||||
case Event::TEXT_ENTERED:
|
||||
// TODO(cwallez) show the character
|
||||
std::cout << "Event: Text Entered" << std::endl;
|
||||
break;
|
||||
case Event::EVENT_KEY_PRESSED:
|
||||
// TODO(cwallez) show the key
|
||||
std::cout << "Event: Key Pressed" << std::endl;
|
||||
break;
|
||||
case Event::EVENT_KEY_RELEASED:
|
||||
// TODO(cwallez) show the key
|
||||
std::cout << "Event: Key Released" << std::endl;
|
||||
break;
|
||||
case Event::EVENT_MOUSE_WHEEL_MOVED:
|
||||
std::cout << "Event: Mouse Wheel (" << event.MouseWheel.Delta << ")" << std::endl;
|
||||
break;
|
||||
case Event::EVENT_MOUSE_BUTTON_PRESSED:
|
||||
std::cout << "Event: Mouse Button Pressed " << MouseButtonName(event.MouseButton.Button) <<
|
||||
" at (" << event.MouseButton.X << ", " << event.MouseButton.Y << ")" << std::endl;
|
||||
break;
|
||||
case Event::EVENT_MOUSE_BUTTON_RELEASED:
|
||||
std::cout << "Event: Mouse Button Released " << MouseButtonName(event.MouseButton.Button) <<
|
||||
" at (" << event.MouseButton.X << ", " << event.MouseButton.Y << ")" << std::endl;
|
||||
break;
|
||||
case Event::EVENT_MOUSE_MOVED:
|
||||
std::cout << "Event: Mouse Moved (" << event.MouseMove.X
|
||||
<< ", " << event.MouseMove.Y << ")" << std::endl;
|
||||
break;
|
||||
case Event::EVENT_MOUSE_ENTERED:
|
||||
std::cout << "Event: Mouse Entered Window" << std::endl;
|
||||
break;
|
||||
case Event::EVENT_MOUSE_LEFT:
|
||||
std::cout << "Event: Mouse Left Window" << std::endl;
|
||||
break;
|
||||
case Event::EVENT_TEST:
|
||||
std::cout << "Event: Test" << std::endl;
|
||||
break;
|
||||
default:
|
||||
UNREACHABLE();
|
||||
break;
|
||||
}
|
||||
}
|
||||
#endif
|
||||
|
||||
OSWindow::OSWindow()
|
||||
: mX(0),
|
||||
mY(0),
|
||||
|
@ -68,6 +163,10 @@ void OSWindow::pushEvent(Event event)
|
|||
}
|
||||
|
||||
mEvents.push_back(event);
|
||||
|
||||
#if DEBUG_EVENTS
|
||||
PrintEvent(event);
|
||||
#endif
|
||||
}
|
||||
|
||||
bool OSWindow::didTestEventFire()
|
||||
|
|
Загрузка…
Ссылка в новой задаче