ViewVC Help
View File | Revision Log | Show Annotations | Download File
/cvs/deliantra/dclient/include/ndk/events.hh
Revision: 1.1
Committed: Sun Oct 24 20:31:43 2010 UTC (13 years, 9 months ago) by sf-pippijn
Branch: MAIN
CVS Tags: HEAD
Log Message:
use EV and plain sockets instead of asio

File Contents

# Content
1 /* events.hh
2 * This file is part of ndk library
3 * Copyright (c) 2003,2004 by Stanislav Ievlev
4 *
5 * This file is covered by the GNU Library General Public License,
6 * which should be included with libndk as the file COPYING.
7 */
8 #pragma once
9
10 #include "key.hh"
11
12 namespace ndk
13 {
14 struct panel;
15 }
16
17 namespace ndk
18 {
19 struct mouse
20 {
21 MEVENT mev;
22
23 int x () const { return mev.x; }
24 int y () const { return mev.y; }
25 bool button1 () const { return (mev.bstate & BUTTON1_CLICKED) == BUTTON1_CLICKED; }
26 bool button2 () const { return (mev.bstate & BUTTON2_CLICKED) == BUTTON2_CLICKED; }
27 bool button3 () const { return (mev.bstate & BUTTON3_CLICKED) == BUTTON3_CLICKED; }
28
29 // check: was the mouse click over a given panel?
30 bool over (panel const &p) const;
31 };
32
33 struct keyboard /**< event from the keyboard */
34 {
35 explicit keyboard (key code, panel *sender = 0)
36 : sender_ (sender)
37 , code_ (code)
38 {
39 }
40
41 panel *sender () const { return sender_; }
42 key code () const { return code_; }
43
44 private:
45 panel *sender_;
46 key const code_; /**< code of the button */
47 };
48
49 struct engine;
50
51 struct event /**< basic NDK internal event */
52 {
53 enum result
54 {
55 ignored = false, /**< event ignored */
56 accepted = true /**< event successfully proceed */
57 };
58
59 event (int t, engine *sender = 0)
60 : sender_ (sender)
61 , type_ (t)
62 {
63 }
64
65 engine *sender_; /**< sender of the envent */
66 int type_; /**< one of the possible types of the event */
67 };
68
69
70 template<typename Ret, typename Tp, typename ArgT>
71 struct slot_fn
72 {
73 slot_fn (Ret (Tp::*f)(ArgT), Tp *obj)
74 : f_ (f)
75 , obj_ (obj)
76 {
77 }
78
79 Ret operator () (ArgT ev) { return (obj_->*f_)(ev); }
80
81 Ret (Tp::*f_)(ArgT);
82 Tp *obj_;
83 };
84
85 template<typename Tp1, typename Tp2>
86 struct slot_fnb
87 {
88 slot_fnb (void (Tp1::*f)(), Tp2 *obj)
89 : f_ (f)
90 , obj_ (obj)
91 {
92 }
93
94 void operator () () { (obj_->*f_)(); }
95
96 void (Tp1::*f_)();
97 Tp2 *obj_;
98 };
99
100 template<typename Tp1, typename Tp2, typename ArgT>
101 struct slot_fnb_1
102 {
103 slot_fnb_1 (void (Tp1::*f)(ArgT), Tp2 *obj, ArgT arg)
104 : f_ (f)
105 , obj_ (obj)
106 , arg_ (arg)
107 {
108 }
109
110 void operator () () { (obj_->*f_)(arg_); }
111
112 void (Tp1::*f_)(ArgT);
113 Tp2 *obj_;
114 ArgT arg_;
115 };
116
117 template<typename Ret, typename Tp, typename ArgT>
118 slot_fn<Ret, Tp, ArgT>
119 slot (Ret (Tp::*f)(ArgT), Tp *obj)
120 {
121 return slot_fn<Ret, Tp, ArgT> (f, obj);
122 }
123
124 template<typename Tp1, typename Tp2>
125 slot_fnb<Tp1, Tp2>
126 slot (void (Tp1::*f)(), Tp2 *obj)
127 {
128 return slot_fnb<Tp1, Tp2> (f, obj);
129 }
130
131 template<typename Tp1, typename Tp2, typename ArgT>
132 slot_fnb_1<Tp1, Tp2, ArgT>
133 slot (void (Tp1::*f)(ArgT), Tp2 *obj, ArgT arg)
134 {
135 return slot_fnb_1<Tp1, Tp2, ArgT> (f, obj, arg);
136 }
137 }