source: libcaca/trunk/csharp/Event.cs @ 2867

Last change on this file since 2867 was 2867, checked in by Sam Hocevar, 11 years ago

Split the C# bindings into separate files.

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