1 | /* |
---|
2 | * CacaSharp .NET bindings for libcaca |
---|
3 | * Copyright (c) 2006 Jean-Yves Lamoureux <jylam@lnxscene.org> |
---|
4 | * All Rights Reserved |
---|
5 | * |
---|
6 | * $Id: Caca.cs 2044 2007-11-24 13:26:28Z sam $ |
---|
7 | * |
---|
8 | * This library is free software. It comes without any warranty, to |
---|
9 | * the extent permitted by applicable law. You can redistribute it |
---|
10 | * and/or modify it under the terms of the Do What The Fuck You Want |
---|
11 | * To Public License, Version 2, as published by Sam Hocevar. See |
---|
12 | * http://sam.zoy.org/wtfpl/COPYING for more details. |
---|
13 | */ |
---|
14 | |
---|
15 | |
---|
16 | |
---|
17 | using System; |
---|
18 | using System.Runtime.InteropServices; |
---|
19 | using System.Security; |
---|
20 | |
---|
21 | using libCucul; |
---|
22 | |
---|
23 | |
---|
24 | namespace libCaca |
---|
25 | { |
---|
26 | |
---|
27 | enum Keys |
---|
28 | { |
---|
29 | CACA_KEY_UNKNOWN = 0x00, /**< Unknown key. */ |
---|
30 | |
---|
31 | /* The following keys have ASCII equivalents */ |
---|
32 | CACA_KEY_BACKSPACE = 0x08, /**< The backspace key. */ |
---|
33 | CACA_KEY_TAB = 0x09, /**< The tabulation key. */ |
---|
34 | CACA_KEY_RETURN = 0x0d, /**< The return key. */ |
---|
35 | CACA_KEY_PAUSE = 0x13, /**< The pause key. */ |
---|
36 | CACA_KEY_ESCAPE = 0x1b, /**< The escape key. */ |
---|
37 | CACA_KEY_DELETE = 0x7f, /**< The delete key. */ |
---|
38 | |
---|
39 | /* The following keys do not have ASCII equivalents but have been |
---|
40 | * chosen to match the SDL equivalents */ |
---|
41 | CACA_KEY_UP = 0x111, /**< The up arrow key. */ |
---|
42 | CACA_KEY_DOWN = 0x112, /**< The down arrow key. */ |
---|
43 | CACA_KEY_LEFT = 0x113, /**< The left arrow key. */ |
---|
44 | CACA_KEY_RIGHT = 0x114, /**< The right arrow key. */ |
---|
45 | |
---|
46 | CACA_KEY_INSERT = 0x115, /**< The insert key. */ |
---|
47 | CACA_KEY_HOME = 0x116, /**< The home key. */ |
---|
48 | CACA_KEY_END = 0x117, /**< The end key. */ |
---|
49 | CACA_KEY_PAGEUP = 0x118, /**< The page up key. */ |
---|
50 | CACA_KEY_PAGEDOWN = 0x119, /**< The page down key. */ |
---|
51 | |
---|
52 | CACA_KEY_F1 = 0x11a, /**< The F1 key. */ |
---|
53 | CACA_KEY_F2 = 0x11b, /**< The F2 key. */ |
---|
54 | CACA_KEY_F3 = 0x11c, /**< The F3 key. */ |
---|
55 | CACA_KEY_F4 = 0x11d, /**< The F4 key. */ |
---|
56 | CACA_KEY_F5 = 0x11e, /**< The F5 key. */ |
---|
57 | CACA_KEY_F6 = 0x11f, /**< The F6 key. */ |
---|
58 | CACA_KEY_F7 = 0x120, /**< The F7 key. */ |
---|
59 | CACA_KEY_F8 = 0x121, /**< The F8 key. */ |
---|
60 | CACA_KEY_F9 = 0x122, /**< The F9 key. */ |
---|
61 | CACA_KEY_F10 = 0x123, /**< The F10 key. */ |
---|
62 | CACA_KEY_F11 = 0x124, /**< The F11 key. */ |
---|
63 | CACA_KEY_F12 = 0x125, /**< The F12 key. */ |
---|
64 | CACA_KEY_F13 = 0x126, /**< The F13 key. */ |
---|
65 | CACA_KEY_F14 = 0x127, /**< The F14 key. */ |
---|
66 | CACA_KEY_F15 = 0x128 /**< The F15 key. */ |
---|
67 | } |
---|
68 | public unsafe class Event |
---|
69 | { |
---|
70 | public enum type |
---|
71 | { |
---|
72 | NONE = 0x0000, /**< No event. */ |
---|
73 | |
---|
74 | KEY_PRESS = 0x0001, /**< A key was pressed. */ |
---|
75 | KEY_RELEASE = 0x0002, /**< A key was released. */ |
---|
76 | MOUSE_PRESS = 0x0004, /**< A mouse button was pressed. */ |
---|
77 | MOUSE_RELEASE = 0x0008, /**< A mouse button was released. */ |
---|
78 | MOUSE_MOTION = 0x0010, /**< The mouse was moved. */ |
---|
79 | RESIZE = 0x0020, /**< The window was resized. */ |
---|
80 | QUIT = 0x0040, /**< The user requested to quit. */ |
---|
81 | |
---|
82 | ANY = 0xffff /**< Bitmask for any event. */ |
---|
83 | }; |
---|
84 | |
---|
85 | } |
---|
86 | |
---|
87 | |
---|
88 | public unsafe class Caca : IDisposable |
---|
89 | { |
---|
90 | [DllImport("libCaca.dll", CallingConvention=CallingConvention.Cdecl), SuppressUnmanagedCodeSecurity] |
---|
91 | public static extern IntPtr caca_create_display(IntPtr qq); |
---|
92 | [DllImport("libCaca.dll", CallingConvention=CallingConvention.Cdecl), SuppressUnmanagedCodeSecurity] |
---|
93 | public static extern void caca_free_display(IntPtr kk); |
---|
94 | [DllImport("libCaca.dll", CallingConvention=CallingConvention.Cdecl), SuppressUnmanagedCodeSecurity] |
---|
95 | public static extern void caca_refresh_display(IntPtr kk); |
---|
96 | [DllImport("libCaca.dll", CallingConvention=CallingConvention.Cdecl), SuppressUnmanagedCodeSecurity] |
---|
97 | public static extern void caca_set_display_time(IntPtr kk, Int32 d); |
---|
98 | [DllImport("libCaca.dll", CallingConvention=CallingConvention.Cdecl), SuppressUnmanagedCodeSecurity] |
---|
99 | public static extern Int32 caca_get_display_time(IntPtr kk); |
---|
100 | [DllImport("libCaca.dll", CallingConvention=CallingConvention.Cdecl), SuppressUnmanagedCodeSecurity] |
---|
101 | public static extern Int32 caca_get_display_width(IntPtr kk); |
---|
102 | [DllImport("libCaca.dll", CallingConvention=CallingConvention.Cdecl), SuppressUnmanagedCodeSecurity] |
---|
103 | public static extern Int32 caca_get_display_height(IntPtr kk); |
---|
104 | [DllImport("libCaca.dll", CallingConvention=CallingConvention.Cdecl), SuppressUnmanagedCodeSecurity] |
---|
105 | public static extern Int32 caca_set_display_title(IntPtr kk, string t); |
---|
106 | [DllImport("libCaca.dll", CallingConvention=CallingConvention.Cdecl), SuppressUnmanagedCodeSecurity] |
---|
107 | public static extern Int32 caca_get_event(IntPtr k, Event.type t, Event e, Int32 timeout); |
---|
108 | [DllImport("libCaca.dll", CallingConvention=CallingConvention.Cdecl), SuppressUnmanagedCodeSecurity] |
---|
109 | public static extern Int32 caca_get_mouse_x(IntPtr k); |
---|
110 | [DllImport("libCaca.dll", CallingConvention=CallingConvention.Cdecl), SuppressUnmanagedCodeSecurity] |
---|
111 | public static extern Int32 caca_get_mouse_y(IntPtr k); |
---|
112 | [DllImport("libCaca.dll", CallingConvention=CallingConvention.Cdecl), SuppressUnmanagedCodeSecurity] |
---|
113 | public static extern void caca_set_mouse(IntPtr k, bool status); |
---|
114 | |
---|
115 | |
---|
116 | |
---|
117 | |
---|
118 | |
---|
119 | IntPtr qq; |
---|
120 | IntPtr kk; |
---|
121 | |
---|
122 | public Caca(Cucul qqt) |
---|
123 | { |
---|
124 | qq = qqt.get_cucul_t(); |
---|
125 | kk = caca_create_display(qq); |
---|
126 | } |
---|
127 | public void Dispose() |
---|
128 | { |
---|
129 | caca_free_display(kk); |
---|
130 | GC.SuppressFinalize(this); |
---|
131 | } |
---|
132 | public void Refresh() |
---|
133 | { |
---|
134 | caca_refresh_display(kk); |
---|
135 | } |
---|
136 | public void setDisplayTime(Int32 d) |
---|
137 | { |
---|
138 | caca_set_display_time(kk, d); |
---|
139 | } |
---|
140 | public Int32 getDisplayTime() |
---|
141 | { |
---|
142 | return caca_get_display_time(kk); |
---|
143 | } |
---|
144 | public Int32 getDisplayWidth() |
---|
145 | { |
---|
146 | return caca_get_display_width(kk); |
---|
147 | } |
---|
148 | public Int32 getDisplayHeight() |
---|
149 | { |
---|
150 | return caca_get_display_height(kk); |
---|
151 | } |
---|
152 | public Int32 setDisplayTitle(string t) |
---|
153 | { |
---|
154 | return caca_set_display_title(kk, t); |
---|
155 | } |
---|
156 | public Int32 getEvent(Event.type t, Event e, Int32 timeout) |
---|
157 | { |
---|
158 | return caca_get_event(kk, t, e, timeout); |
---|
159 | } |
---|
160 | public Int32 getMouseX() |
---|
161 | { |
---|
162 | return caca_get_mouse_x(kk); |
---|
163 | } |
---|
164 | public Int32 getMouseY() |
---|
165 | { |
---|
166 | return caca_get_mouse_y(kk); |
---|
167 | } |
---|
168 | public void caca_set_mouse(bool status) |
---|
169 | { |
---|
170 | caca_set_mouse(kk, status); |
---|
171 | } |
---|
172 | |
---|
173 | |
---|
174 | |
---|
175 | |
---|
176 | |
---|
177 | |
---|
178 | |
---|
179 | public IntPtr get_caca_t() |
---|
180 | { |
---|
181 | return kk; |
---|
182 | } |
---|
183 | |
---|
184 | |
---|
185 | } |
---|
186 | } |
---|