Debian Codegraph @

caca-sharp/Event.cs

raw
1 /*
2 * libcaca .NET bindings for libcaca
3 * Copyright (c) 2006 Jean-Yves Lamoureux <[email protected]>
4 * 2007 Sam Hocevar <[email protected]>
5 * All Rights Reserved
6 *
7 * This library is free software. It comes without any warranty, to
8 * the extent permitted by applicable law. You can redistribute it
9 * and/or modify it under the terms of the Do What the Fuck You Want
10 * to Public License, Version 2, as published by Sam Hocevar. See
11 * http://www.wtfpl.net/ for more details.
12 */
13
14 using System;
15 using System.Runtime.InteropServices;
16 using System.Security;
17 using System.Drawing;
18
19 namespace Caca
20 {
21 public enum EventType
22 {
23 NONE = 0x0000,
24
25 KEY_PRESS = 0x0001,
26 KEY_RELEASE = 0x0002,
27 MOUSE_PRESS = 0x0004,
28 MOUSE_RELEASE = 0x0008,
29 MOUSE_MOTION = 0x0010,
30 RESIZE = 0x0020,
31 QUIT = 0x0040,
32
33 ANY = 0xffff,
34 }
35
36 public enum EventKey
37 {
38 UNKNOWN = 0x00,
39
40 CTRL_A = 0x01,
41 CTRL_B = 0x02,
42 CTRL_C = 0x03,
43 CTRL_D = 0x04,
44 CTRL_E = 0x05,
45 CTRL_F = 0x06,
46 CTRL_G = 0x07,
47 BACKSPACE = 0x08,
48 TAB = 0x09,
49 CTRL_J = 0x0a,
50 CTRL_K = 0x0b,
51 CTRL_L = 0x0c,
52 RETURN = 0x0d,
53 CTRL_N = 0x0e,
54 CTRL_O = 0x0f,
55 CTRL_P = 0x10,
56 CTRL_Q = 0x11,
57 CTRL_R = 0x12,
58 PAUSE = 0x13,
59 CTRL_T = 0x14,
60 CTRL_U = 0x15,
61 CTRL_V = 0x16,
62 CTRL_W = 0x17,
63 CTRL_X = 0x18,
64 CTRL_Y = 0x19,
65 CTRL_Z = 0x1a,
66 ESCAPE = 0x1b,
67 DELETE = 0x7f,
68
69 UP = 0x111,
70 DOWN = 0x112,
71 LEFT = 0x113,
72 RIGHT = 0x114,
73
74 INSERT = 0x115,
75 HOME = 0x116,
76 END = 0x117,
77 PAGEUP = 0x118,
78 PAGEDOWN = 0x119,
79
80 F1 = 0x11a,
81 F2 = 0x11b,
82 F3 = 0x11c,
83 F4 = 0x11d,
84 F5 = 0x11e,
85 F6 = 0x11f,
86 F7 = 0x120,
87 F8 = 0x121,
88 F9 = 0x122,
89 F10 = 0x123,
90 F11 = 0x124,
91 F12 = 0x125,
92 F13 = 0x126,
93 F14 = 0x127,
94 F15 = 0x128,
95 }
96
97 public class Event : IDisposable
98 {
99 public IntPtr cevent;
100 private IntPtr _utf8;
101
102 public Event()
103 {
104 cevent = Marshal.AllocHGlobal(32);
105 _utf8 = Marshal.AllocHGlobal(8);
106 }
107
108 public void Dispose()
109 {
110 Marshal.FreeHGlobal(cevent);
111 Marshal.FreeHGlobal(_utf8);
112 GC.SuppressFinalize(this);
113 }
114
115 [DllImport("libcaca.dll", CallingConvention=CallingConvention.Cdecl),
116 SuppressUnmanagedCodeSecurity]
117 private static extern int caca_get_event_type(IntPtr ev);
118 public EventType Type
119 {
120 get { return (EventType)caca_get_event_type(cevent); }
121 }
122
123 [DllImport("libcaca.dll", CallingConvention=CallingConvention.Cdecl),
124 SuppressUnmanagedCodeSecurity]
125 private static extern int caca_get_event_key_ch(IntPtr ev);
126 public int KeyCh
127 {
128 get { return caca_get_event_key_ch(cevent); }
129 }
130
131 [DllImport("libcaca.dll", CallingConvention=CallingConvention.Cdecl),
132 SuppressUnmanagedCodeSecurity]
133 private static extern uint caca_get_event_key_utf32(IntPtr ev);
134 public uint KeyUtf32
135 {
136 get { return caca_get_event_key_utf32(cevent); }
137 }
138
139 [DllImport("libcaca.dll", CallingConvention=CallingConvention.Cdecl),
140 SuppressUnmanagedCodeSecurity]
141 private static extern int caca_get_event_key_utf8(IntPtr ev,
142 IntPtr _utf8);
143 public string KeyUtf8
144 {
145 get
146 {
147 caca_get_event_key_utf8(cevent, _utf8);
148 return Marshal.PtrToStringAnsi(_utf8);
149 }
150 }
151
152 [DllImport("libcaca.dll", CallingConvention=CallingConvention.Cdecl),
153 SuppressUnmanagedCodeSecurity]
154 private static extern int caca_get_event_mouse_button(IntPtr ev);
155 public int MouseButton
156 {
157 get { return caca_get_event_mouse_button(cevent); }
158 }
159
160 [DllImport("libcaca.dll", CallingConvention=CallingConvention.Cdecl),
161 SuppressUnmanagedCodeSecurity]
162 private static extern int caca_get_event_mouse_x(IntPtr ev);
163 [DllImport("libcaca.dll", CallingConvention=CallingConvention.Cdecl),
164 SuppressUnmanagedCodeSecurity]
165 private static extern int caca_get_event_mouse_y(IntPtr ev);
166 public Point MousePos
167 {
168 get { return new Point(caca_get_event_mouse_x(cevent),
169 caca_get_event_mouse_y(cevent)); }
170 }
171
172 [DllImport("libcaca.dll", CallingConvention=CallingConvention.Cdecl),
173 SuppressUnmanagedCodeSecurity]
174 private static extern int caca_get_event_resize_width(IntPtr ev);
175 [DllImport("libcaca.dll", CallingConvention=CallingConvention.Cdecl),
176 SuppressUnmanagedCodeSecurity]
177 private static extern int caca_get_event_resize_height(IntPtr ev);
178 public Size ResizeSize
179 {
180 get { return new Size(caca_get_event_resize_width(cevent),
181 caca_get_event_resize_height(cevent)); }
182 }
183 }
184 }
185