Responder.h
1 /* Copyright (C) 2015-2024 Marc Boris Duerner
2 
3  This library is free software; you can redistribute it and/or
4  modify it under the terms of the GNU Lesser General Public
5  License as published by the Free Software Foundation; either
6  version 2.1 of the License, or (at your option) any later version.
7 
8  As a special exception, you may use this file as part of a free
9  software library without restriction. Specifically, if other files
10  instantiate templates or use macros or inline functions from this
11  file, or you compile this file and link it with other files to
12  produce an executable, this file does not by itself cause the
13  resulting executable to be covered by the GNU General Public
14  License. This exception does not however invalidate any other
15  reasons why the executable file might be covered by the GNU Library
16  General Public License.
17 
18  This library is distributed in the hope that it will be useful,
19  but WITHOUT ANY WARRANTY; without even the implied warranty of
20  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
21  Lesser General Public License for more details.
22 
23  You should have received a copy of the GNU Lesser General Public
24  License along with this library; if not, write to the Free Software
25  Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston,
26  MA 02110-1301 USA
27 */
28 
29 #ifndef PT_FORMS_RESPONDER_H
30 #define PT_FORMS_RESPONDER_H
31 
32 #include <Pt/Forms/Api.h>
33 #include <Pt/Gfx/Point.h>
34 
35 namespace Pt {
36 
37 namespace Forms {
38 
39 class MouseEvent;
40 class TouchEvent;
41 class ScrollEvent;
42 class EnterEvent;
43 class LeaveEvent;
44 class KeyEvent;
45 
59 class PT_FORMS_API Responder
60 {
61  protected:
65 
66  public:
69  virtual ~Responder();
70 
76  bool mouseEvent(const MouseEvent& ev);
77 
82  void touchEvent(const TouchEvent& ev);
83 
86  void scrollEvent(const ScrollEvent& ev);
87 
90  void enterEvent(const EnterEvent& ev);
91 
94  void leaveEvent(const LeaveEvent& ev);
95 
98  void keyEvent(const KeyEvent& ev);
99 
100  protected:
103  virtual Responder* onNextResponder() = 0;
104 
107  virtual Gfx::PointF onToGlobal(const Gfx::PointF& pos) const = 0;
108 
111  virtual Gfx::PointF onFromGlobal(const Gfx::PointF& pos) const = 0;
112 
113  protected:
118  virtual bool onMouseEvent(const MouseEvent& ev);
119 
124  virtual bool onTouchEvent(const TouchEvent& ev);
125 
130  virtual bool onScrollEvent(const ScrollEvent& ev);
131 
136  virtual bool onEnterEvent(const EnterEvent& ev);
137 
142  virtual bool onLeaveEvent(const LeaveEvent& ev);
143 
148  virtual bool onKeyEvent(const KeyEvent& ev);
149 
150  protected:
153  virtual bool onMousePress(const MouseEvent& ev)
154  { return false; }
155 
158  virtual bool onMouseRelease(const MouseEvent& ev)
159  { return false; }
160 
163  virtual bool onMouseMove(const MouseEvent& ev)
164  { return false; }
165 };
166 
167 } // namespace
168 
169 } // namespace
170 
171 #endif // include guard
Core module.
Definition: Allocator.h:33
Key press or release.
Definition: KeyEvent.h:50
Touch press, move, or release.
Definition: TouchEvent.h:51
Pointer entered a widget.
Definition: EnterEvent.h:49
Scroll or wheel movement.
Definition: ScrollEvent.h:51
virtual bool onMouseMove(const MouseEvent &ev)
Handles a mouse move. The default returns false.
Definition: Responder.h:163
virtual Responder * onNextResponder()=0
Returns the next responder, or 0 at the end of the chain.
void touchEvent(const TouchEvent &ev)
Delivers ev along the touch responder chain.
virtual bool onKeyEvent(const KeyEvent &ev)
Handles a key event.
virtual bool onLeaveEvent(const LeaveEvent &ev)
Handles pointer leave.
Point with floating-point X and Y coordinates.
Definition: Point.h:47
void keyEvent(const KeyEvent &ev)
Delivers ev along the key responder chain.
virtual bool onScrollEvent(const ScrollEvent &ev)
Handles a scroll event.
virtual ~Responder()
Destructor.
void scrollEvent(const ScrollEvent &ev)
Delivers ev along the scroll responder chain.
virtual Gfx::PointF onToGlobal(const Gfx::PointF &pos) const =0
Converts local position pos to global coordinates.
virtual bool onMousePress(const MouseEvent &ev)
Handles a mouse press. The default returns false.
Definition: Responder.h:153
virtual bool onMouseRelease(const MouseEvent &ev)
Handles a mouse release. The default returns false.
Definition: Responder.h:158
virtual bool onMouseEvent(const MouseEvent &ev)
Handles a mouse event in local coordinates.
virtual Gfx::PointF onFromGlobal(const Gfx::PointF &pos) const =0
Converts global position pos to local coordinates.
void enterEvent(const EnterEvent &ev)
Delivers ev along the enter responder chain.
virtual bool onEnterEvent(const EnterEvent &ev)
Handles pointer entry.
Pointer left a widget.
Definition: LeaveEvent.h:49
virtual bool onTouchEvent(const TouchEvent &ev)
Handles a touch event in local coordinates.
Object that handles input or forwards it.
Definition: Responder.h:60
Pointer movement or button change.
Definition: MouseEvent.h:134
bool mouseEvent(const MouseEvent &ev)
Delivers ev along the mouse responder chain.
Responder()
Creates a responder.
void leaveEvent(const LeaveEvent &ev)
Delivers ev along the leave responder chain.