Inkscape
Vector Graphics Editor
Loading...
Searching...
No Matches
debug.h
Go to the documentation of this file.
1// SPDX-License-Identifier: GPL-2.0-or-later
2#ifndef INKSCAPE_UI_WIDGET_EVENTS_DEBUG_H
3#define INKSCAPE_UI_WIDGET_EVENTS_DEBUG_H
8/*
9 * Released under GNU GPL v2+, read the file 'COPYING' for more information.
10 */
11
13
14namespace Inkscape {
15
19inline constexpr bool DEBUG_EVENTS = false;
20
28inline void dump_event(CanvasEvent const &event, char const *prefix, bool merge = true)
29{
30 static EventType old_type = EventType::NUM_EVENTS;
31 static unsigned count = 0;
32
33 // Doesn't usually help to dump a zillion motion notify events.
34 ++count;
35 if (merge && event.type() == old_type && event.type() == EventType::MOTION) {
36 if (count == 1) {
37 std::cout << prefix << " ... ditto" << std::endl;
38 }
39 return;
40 }
41
42 count = 0;
43 old_type = event.type();
44
45 std::cout << prefix << ": ";
46
47 inspect_event(event,
48 [] (ButtonPressEvent const &event) {
49 std::cout << "ButtonPressEvent: " << event.button;
50 if (auto n = event.num_press; n != 1) {
51 std::cout << " num_press: " << n;
52 }
53 std::cout << std::endl;
54 },
55 [] (ButtonReleaseEvent const &event) {
56 std::cout << "ButtonReleaseEvent: " << event.button << std::endl;
57 },
58
59 [] (KeyPressEvent const &event) {
60 std::cout << "KeyPressEvent: " << std::hex
61 << " keycode: " << event.keycode
62 << " state: " << event.modifiers
63 << " keyval: " << event.keyval << std::endl;
64 },
65 [] (KeyReleaseEvent const &event) {
66 std::cout << "KeyReleaseEvent: " << event.keycode << std::endl;
67 },
68
69 [] (MotionEvent const &event) {
70 std::cout << "MotionEvent" << std::endl;
71 },
72 [] (EnterEvent const &event) {
73 std::cout << "EnterEvent" << std::endl;
74 },
75 [] (LeaveEvent const &event) {
76 std::cout << "LeaveEvent" << std::endl;
77 },
78
79 [] (ScrollEvent const &event) {
80 std::cout << "ScrollEvent" << std::endl;
81 }
82 );
83}
84
85} // namespace Inkscape
86
87#endif // INKSCAPE_UI_WIDGET_EVENTS_DEBUG_H
88
89/*
90 Local Variables:
91 mode:c++
92 c-file-style:"stroustrup"
93 c-file-offsets:((innamespace . 0)(inline-open . 0)(case-label . +))
94 indent-tabs-mode:nil
95 fill-column:99
96 End:
97*/
98// vim: filetype=cpp:expandtab:shiftwidth=4:tabstop=8:softtabstop=4 :
Helper class to stream background task notifications as a series of messages.
EventType
The type of a CanvasEvent.
Definition enums.h:20
void inspect_event(E &&event, Fs... funcs)
Perform pattern-matching on a CanvasEvent.
void dump_event(CanvasEvent const &event, char const *prefix, bool merge=true)
Print an event to stdout.
Definition debug.h:28
constexpr bool DEBUG_EVENTS
Whether event debug printing is enabled.
Definition debug.h:19
A mouse button (left/right/middle) is pressed.
A mouse button (left/right/middle) is released.
Abstract base class for events.
virtual EventType type() const =0
Return the dynamic type of the CanvasEvent.
The pointer has entered a widget or item.
A key has been pressed.
A key has been released.
The pointer has exited a widget or item.
Movement of the mouse pointer.
Scroll the item or widget by the provided amount.