bWidgets
Core widget toolkit designed for Blender
EventHandler.h
Go to the documentation of this file.
1#pragma once
2
3#include <array>
4#include <functional>
5#include <list>
6#include <unordered_map>
7
8namespace bWidgets {
9
10class bwEvent;
11class bwMouseButtonEvent;
12class bwMouseButtonDragEvent;
13class bwMouseWheelEvent;
14
15namespace bwScreenGraph {
16
17class Node;
18
19// TODO bwHandlingContext
20using EventListener = std::function<void(Node&)>;
21
32 public:
33 enum EventType {
36
38 };
39
40 EventHandler() = default;
41 virtual ~EventHandler() = default;
42
43 void addEventListener(EventType event_type, EventListener listener);
44
45 virtual void onMouseMove(bwEvent&);
46 virtual void onMouseEnter(bwEvent&);
47 virtual void onMouseLeave(bwEvent&);
48 virtual void onMousePress(bwMouseButtonEvent&);
50 virtual void onMouseClick(bwMouseButtonEvent&);
52 virtual void onMouseWheel(bwMouseWheelEvent&);
53
54 private:
55 std::array<std::list<EventListener>, TOT_EVENT_TYPES> listeners;
56 // std::unordered_map<EventType, std::list<EventListener>> listener_map;
57};
58
59} // namespace bwScreenGraph
60} // namespace bWidgets
Definition: bwEvent.h:8
Definition: bwEvent.h:39
Definition: bwEvent.h:24
Definition: bwEvent.h:56
API for registering and calling event-listeners.
Definition: EventHandler.h:31
virtual void onMouseMove(bwEvent &)
Definition: EventHandler.cc:16
virtual void onMouseDrag(bwMouseButtonDragEvent &)
Definition: EventHandler.cc:40
virtual void onMouseWheel(bwMouseWheelEvent &)
Definition: EventHandler.cc:44
virtual void onMousePress(bwMouseButtonEvent &)
Definition: EventHandler.cc:28
void addEventListener(EventType event_type, EventListener listener)
Definition: EventHandler.cc:10
EventType
Definition: EventHandler.h:33
@ MOUSE_ENTER
Definition: EventHandler.h:34
@ TOT_EVENT_TYPES
Definition: EventHandler.h:37
@ MOUSE_LEAVE
Definition: EventHandler.h:35
virtual void onMouseEnter(bwEvent &)
Definition: EventHandler.cc:20
virtual void onMouseLeave(bwEvent &)
Definition: EventHandler.cc:24
virtual void onMouseClick(bwMouseButtonEvent &)
Definition: EventHandler.cc:36
virtual void onMouseRelease(bwMouseButtonEvent &)
Definition: EventHandler.cc:32
The base data-structure for a screen-graph node.
Definition: Node.h:36
std::function< void(Node &)> EventListener
Definition: EventHandler.h:20
Definition: bwContext.h:3