Changeset 2052 for libcaca/trunk/csharp
- Timestamp:
- Nov 25, 2007, 12:12:25 PM (13 years ago)
- Location:
- libcaca/trunk/csharp
- Files:
-
- 2 edited
Legend:
- Unmodified
- Added
- Removed
-
libcaca/trunk/csharp/Caca.cs
r2047 r2052 21 21 namespace Caca 22 22 { 23 24 enum Keys 25 { 26 CACA_KEY_UNKNOWN = 0x00, /**< Unknown key. */ 27 28 /* The following keys have ASCII equivalents */ 29 CACA_KEY_BACKSPACE = 0x08, /**< The backspace key. */ 30 CACA_KEY_TAB = 0x09, /**< The tabulation key. */ 31 CACA_KEY_RETURN = 0x0d, /**< The return key. */ 32 CACA_KEY_PAUSE = 0x13, /**< The pause key. */ 33 CACA_KEY_ESCAPE = 0x1b, /**< The escape key. */ 34 CACA_KEY_DELETE = 0x7f, /**< The delete key. */ 35 36 /* The following keys do not have ASCII equivalents but have been 37 * chosen to match the SDL equivalents */ 38 CACA_KEY_UP = 0x111, /**< The up arrow key. */ 39 CACA_KEY_DOWN = 0x112, /**< The down arrow key. */ 40 CACA_KEY_LEFT = 0x113, /**< The left arrow key. */ 41 CACA_KEY_RIGHT = 0x114, /**< The right arrow key. */ 42 43 CACA_KEY_INSERT = 0x115, /**< The insert key. */ 44 CACA_KEY_HOME = 0x116, /**< The home key. */ 45 CACA_KEY_END = 0x117, /**< The end key. */ 46 CACA_KEY_PAGEUP = 0x118, /**< The page up key. */ 47 CACA_KEY_PAGEDOWN = 0x119, /**< The page down key. */ 48 49 CACA_KEY_F1 = 0x11a, /**< The F1 key. */ 50 CACA_KEY_F2 = 0x11b, /**< The F2 key. */ 51 CACA_KEY_F3 = 0x11c, /**< The F3 key. */ 52 CACA_KEY_F4 = 0x11d, /**< The F4 key. */ 53 CACA_KEY_F5 = 0x11e, /**< The F5 key. */ 54 CACA_KEY_F6 = 0x11f, /**< The F6 key. */ 55 CACA_KEY_F7 = 0x120, /**< The F7 key. */ 56 CACA_KEY_F8 = 0x121, /**< The F8 key. */ 57 CACA_KEY_F9 = 0x122, /**< The F9 key. */ 58 CACA_KEY_F10 = 0x123, /**< The F10 key. */ 59 CACA_KEY_F11 = 0x124, /**< The F11 key. */ 60 CACA_KEY_F12 = 0x125, /**< The F12 key. */ 61 CACA_KEY_F13 = 0x126, /**< The F13 key. */ 62 CACA_KEY_F14 = 0x127, /**< The F14 key. */ 63 CACA_KEY_F15 = 0x128 /**< The F15 key. */ 64 } 65 public unsafe class Event 66 { 67 public enum type 68 { 69 NONE = 0x0000, /**< No event. */ 70 71 KEY_PRESS = 0x0001, /**< A key was pressed. */ 72 KEY_RELEASE = 0x0002, /**< A key was released. */ 73 MOUSE_PRESS = 0x0004, /**< A mouse button was pressed. */ 74 MOUSE_RELEASE = 0x0008, /**< A mouse button was released. */ 75 MOUSE_MOTION = 0x0010, /**< The mouse was moved. */ 76 RESIZE = 0x0020, /**< The window was resized. */ 77 QUIT = 0x0040, /**< The user requested to quit. */ 78 79 ANY = 0xffff /**< Bitmask for any event. */ 80 }; 81 82 } 83 84 85 public unsafe class CacaDisplay : IDisposable 86 { 87 [DllImport("libcaca.dll", CallingConvention=CallingConvention.Cdecl), SuppressUnmanagedCodeSecurity] 88 public static extern IntPtr caca_create_display(IntPtr cv); 89 [DllImport("libcaca.dll", CallingConvention=CallingConvention.Cdecl), SuppressUnmanagedCodeSecurity] 90 public static extern void caca_free_display(IntPtr dp); 91 [DllImport("libcaca.dll", CallingConvention=CallingConvention.Cdecl), SuppressUnmanagedCodeSecurity] 92 public static extern void caca_refresh_display(IntPtr dp); 93 [DllImport("libcaca.dll", CallingConvention=CallingConvention.Cdecl), SuppressUnmanagedCodeSecurity] 94 public static extern void caca_set_display_time(IntPtr dp, Int32 d); 95 [DllImport("libcaca.dll", CallingConvention=CallingConvention.Cdecl), SuppressUnmanagedCodeSecurity] 96 public static extern Int32 caca_get_display_time(IntPtr dp); 97 [DllImport("libcaca.dll", CallingConvention=CallingConvention.Cdecl), SuppressUnmanagedCodeSecurity] 98 public static extern Int32 caca_get_display_width(IntPtr dp); 99 [DllImport("libcaca.dll", CallingConvention=CallingConvention.Cdecl), SuppressUnmanagedCodeSecurity] 100 public static extern Int32 caca_get_display_height(IntPtr dp); 101 [DllImport("libcaca.dll", CallingConvention=CallingConvention.Cdecl), SuppressUnmanagedCodeSecurity] 102 public static extern Int32 caca_set_display_title(IntPtr dp, string t); 103 [DllImport("libcaca.dll", CallingConvention=CallingConvention.Cdecl), SuppressUnmanagedCodeSecurity] 104 public static extern Int32 caca_get_event(IntPtr k, Event.type t, Event e, Int32 timeout); 105 [DllImport("libcaca.dll", CallingConvention=CallingConvention.Cdecl), SuppressUnmanagedCodeSecurity] 106 public static extern Int32 caca_get_mouse_x(IntPtr k); 107 [DllImport("libcaca.dll", CallingConvention=CallingConvention.Cdecl), SuppressUnmanagedCodeSecurity] 108 public static extern Int32 caca_get_mouse_y(IntPtr k); 109 [DllImport("libcaca.dll", CallingConvention=CallingConvention.Cdecl), SuppressUnmanagedCodeSecurity] 110 public static extern void caca_set_mouse(IntPtr k, bool status); 111 112 113 114 115 116 IntPtr _cv; 117 IntPtr _dp; 118 119 public CacaDisplay(CuculCanvas cv) 120 { 121 _cv = cv._cv; 122 _dp = caca_create_display(_cv); 123 } 124 public void Dispose() 125 { 126 caca_free_display(_dp); 127 GC.SuppressFinalize(this); 128 } 129 public void Refresh() 130 { 131 caca_refresh_display(_dp); 132 } 133 public void setDisplayTime(Int32 d) 134 { 135 caca_set_display_time(_dp, d); 136 } 137 public Int32 getDisplayTime() 138 { 139 return caca_get_display_time(_dp); 140 } 141 public Int32 getDisplayWidth() 142 { 143 return caca_get_display_width(_dp); 144 } 145 public Int32 getDisplayHeight() 146 { 147 return caca_get_display_height(_dp); 148 } 149 public Int32 setDisplayTitle(string t) 150 { 151 return caca_set_display_title(_dp, t); 152 } 153 public Int32 getEvent(Event.type t, Event e, Int32 timeout) 154 { 155 return caca_get_event(_dp, t, e, timeout); 156 } 157 public Int32 getMouseX() 158 { 159 return caca_get_mouse_x(_dp); 160 } 161 public Int32 getMouseY() 162 { 163 return caca_get_mouse_y(_dp); 164 } 165 public void caca_set_mouse(bool status) 166 { 167 caca_set_mouse(_dp, status); 168 } 169 170 171 172 173 174 175 176 public IntPtr get_caca_t() 177 { 178 return _dp; 179 } 23 public enum CacaEventType 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 CacaEventKey 39 { 40 UNKNOWN = 0x00, 41 42 BACKSPACE = 0x08, 43 TAB = 0x09, 44 RETURN = 0x0d, 45 PAUSE = 0x13, 46 ESCAPE = 0x1b, 47 DELETE = 0x7f, 48 49 UP = 0x111, 50 DOWN = 0x112, 51 LEFT = 0x113, 52 RIGHT = 0x114, 53 54 INSERT = 0x115, 55 HOME = 0x116, 56 END = 0x117, 57 PAGEUP = 0x118, 58 PAGEDOWN = 0x119, 59 60 F1 = 0x11a, 61 F2 = 0x11b, 62 F3 = 0x11c, 63 F4 = 0x11d, 64 F5 = 0x11e, 65 F6 = 0x11f, 66 F7 = 0x120, 67 F8 = 0x121, 68 F9 = 0x122, 69 F10 = 0x123, 70 F11 = 0x124, 71 F12 = 0x125, 72 F13 = 0x126, 73 F14 = 0x127, 74 F15 = 0x128, 75 } 76 77 public class CacaEvent : IDisposable 78 { 79 public IntPtr cevent; 80 private IntPtr utf8; 81 82 public CacaEvent() 83 { 84 cevent = Marshal.AllocHGlobal(32); 85 utf8 = Marshal.AllocHGlobal(8); 86 } 87 88 public void Dispose() 89 { 90 Marshal.FreeHGlobal(cevent); 91 Marshal.FreeHGlobal(utf8); 92 GC.SuppressFinalize(this); 93 } 94 95 [DllImport("libcaca.dll", CallingConvention=CallingConvention.Cdecl), 96 SuppressUnmanagedCodeSecurity] 97 private static extern int caca_get_event_type(IntPtr ev); 98 public CacaEventType type 99 { 100 get { return (CacaEventType)caca_get_event_type(cevent); } 101 } 102 103 [DllImport("libcaca.dll", CallingConvention=CallingConvention.Cdecl), 104 SuppressUnmanagedCodeSecurity] 105 private static extern int caca_get_event_key_ch(IntPtr ev); 106 public int keyCh 107 { 108 get { return caca_get_event_key_ch(cevent); } 109 } 110 111 [DllImport("libcaca.dll", CallingConvention=CallingConvention.Cdecl), 112 SuppressUnmanagedCodeSecurity] 113 private static extern int caca_get_event_key_utf32(IntPtr ev); 114 public int keyUtf32 115 { 116 get { return caca_get_event_key_utf32(cevent); } 117 } 118 119 [DllImport("libcaca.dll", CallingConvention=CallingConvention.Cdecl), 120 SuppressUnmanagedCodeSecurity] 121 private static extern int caca_get_event_key_utf8(IntPtr ev, 122 IntPtr utf8); 123 public string keyUtf8 124 { 125 get 126 { 127 caca_get_event_key_utf8(cevent, utf8); 128 return Marshal.PtrToStringUni(utf8); 129 } 130 } 131 132 [DllImport("libcaca.dll", CallingConvention=CallingConvention.Cdecl), 133 SuppressUnmanagedCodeSecurity] 134 private static extern int caca_get_event_mouse_button(IntPtr ev); 135 public int mouseButton 136 { 137 get { return caca_get_event_mouse_button(cevent); } 138 } 139 140 [DllImport("libcaca.dll", CallingConvention=CallingConvention.Cdecl), 141 SuppressUnmanagedCodeSecurity] 142 private static extern int caca_get_event_mouse_x(IntPtr ev); 143 public int mouseX 144 { 145 get { return caca_get_event_mouse_x(cevent); } 146 } 147 148 [DllImport("libcaca.dll", CallingConvention=CallingConvention.Cdecl), 149 SuppressUnmanagedCodeSecurity] 150 private static extern int caca_get_event_mouse_y(IntPtr ev); 151 public int mouseY 152 { 153 get { return caca_get_event_mouse_y(cevent); } 154 } 155 156 [DllImport("libcaca.dll", CallingConvention=CallingConvention.Cdecl), 157 SuppressUnmanagedCodeSecurity] 158 private static extern int caca_get_event_resize_width(IntPtr ev); 159 public int resizeWidth 160 { 161 get { return caca_get_event_resize_width(cevent); } 162 } 163 164 [DllImport("libcaca.dll", CallingConvention=CallingConvention.Cdecl), 165 SuppressUnmanagedCodeSecurity] 166 private static extern int caca_get_event_resize_height(IntPtr ev); 167 public int resizeHeight 168 { 169 get { return caca_get_event_resize_height(cevent); } 170 } 171 } 172 173 public unsafe class CacaDisplay : IDisposable 174 { 175 private IntPtr _cv; 176 private IntPtr _dp; 177 178 [DllImport("libcaca.dll", CallingConvention=CallingConvention.Cdecl), 179 SuppressUnmanagedCodeSecurity] 180 private static extern IntPtr caca_create_display(IntPtr cv); 181 public CacaDisplay(CuculCanvas cv) 182 { 183 _cv = cv._cv; 184 _dp = caca_create_display(_cv); 185 } 186 187 [DllImport("libcaca.dll", CallingConvention=CallingConvention.Cdecl), 188 SuppressUnmanagedCodeSecurity] 189 private static extern void caca_free_display(IntPtr dp); 190 public void Dispose() 191 { 192 caca_free_display(_dp); 193 GC.SuppressFinalize(this); 194 } 195 196 [DllImport("libcaca.dll", CallingConvention=CallingConvention.Cdecl), 197 SuppressUnmanagedCodeSecurity] 198 private static extern void caca_refresh_display(IntPtr dp); 199 public void Refresh() 200 { 201 caca_refresh_display(_dp); 202 } 203 204 [DllImport("libcaca.dll", CallingConvention=CallingConvention.Cdecl), 205 SuppressUnmanagedCodeSecurity] 206 private static extern void caca_set_display_time(IntPtr dp, int d); 207 [DllImport("libcaca.dll", CallingConvention=CallingConvention.Cdecl), 208 SuppressUnmanagedCodeSecurity] 209 private static extern int caca_get_display_time(IntPtr dp); 210 public int displayTime 211 { 212 get { return caca_get_display_time(_dp); } 213 set { caca_set_display_time(_dp, value); } 214 } 215 216 [DllImport("libcaca.dll", CallingConvention=CallingConvention.Cdecl), 217 SuppressUnmanagedCodeSecurity] 218 private static extern int caca_get_event(IntPtr dp, int t, 219 IntPtr cevent, 220 int timeout); 221 public CacaEvent getEvent(CacaEventType t, int timeout) 222 { 223 CacaEvent e = new CacaEvent(); 224 caca_get_event(_dp, (int)t, e.cevent, timeout); 225 return e; 226 } 227 228 [DllImport("libcaca.dll", CallingConvention=CallingConvention.Cdecl), 229 SuppressUnmanagedCodeSecurity] 230 private static extern int caca_get_display_width(IntPtr dp); 231 public int width 232 { 233 get { return caca_get_display_width(_dp); } 234 } 235 236 [DllImport("libcaca.dll", CallingConvention=CallingConvention.Cdecl), 237 SuppressUnmanagedCodeSecurity] 238 private static extern int caca_get_display_height(IntPtr dp); 239 public int height 240 { 241 get { return caca_get_display_height(_dp); } 242 } 243 244 [DllImport("libcaca.dll", CallingConvention=CallingConvention.Cdecl), 245 SuppressUnmanagedCodeSecurity] 246 private static extern int caca_set_display_title(IntPtr dp, string t); 247 public string title 248 { 249 set { caca_set_display_title(_dp, value); } 250 } 251 252 [DllImport("libcaca.dll", CallingConvention=CallingConvention.Cdecl), 253 SuppressUnmanagedCodeSecurity] 254 private static extern void caca_set_mouse(IntPtr k, bool status); 255 public bool mouse 256 { 257 set { caca_set_mouse(_dp, value); } 258 } 259 260 [DllImport("libcaca.dll", CallingConvention=CallingConvention.Cdecl), 261 SuppressUnmanagedCodeSecurity] 262 private static extern int caca_get_mouse_x(IntPtr k); 263 public int mouseX 264 { 265 get { return caca_get_mouse_x(_dp); } 266 } 267 268 [DllImport("libcaca.dll", CallingConvention=CallingConvention.Cdecl), 269 SuppressUnmanagedCodeSecurity] 270 private static extern int caca_get_mouse_y(IntPtr k); 271 public int mouseY 272 { 273 get { return caca_get_mouse_y(_dp); } 274 } 275 276 [DllImport("libcaca.dll", CallingConvention=CallingConvention.Cdecl), 277 SuppressUnmanagedCodeSecurity] 278 private static extern void caca_set_cursor(IntPtr k, bool status); 279 public bool cursor 280 { 281 set { caca_set_cursor(_dp, value); } 282 } 180 283 } 181 284 } -
libcaca/trunk/csharp/test.cs
r2047 r2052 59 59 class DemoDisplay : CacaDisplay 60 60 { 61 private Event e;62 61 private DemoCanvas cv; 63 62 64 63 public DemoDisplay(DemoCanvas _cv) : base(_cv) 65 64 { 66 setDisplayTime(20000); // Refresh every 20 ms67 setDisplayTitle("libcaca .NET Bindings test suite");65 displayTime = 20000; // Refresh every 20 ms 66 title = "libcaca .NET Bindings test suite"; 68 67 cv = _cv; 69 e = new Event();70 68 } 71 69 72 70 public void EventLoop() 73 71 { 74 while(getEvent(Event.type.KEY_RELEASE, e, 10) == 0) 72 CacaEvent ev; 73 74 while((ev = getEvent(CacaEventType.KEY_RELEASE, 10)).type == 0) 75 75 { 76 76 cv.Draw(); … … 78 78 Refresh(); 79 79 } 80 81 if(ev.keyCh > 0x20 && ev.keyCh < 0x7f) 82 Console.WriteLine("Key pressed: {0}", ev.keyUtf8); 83 else 84 Console.WriteLine("Key pressed: 0x{0:x}", ev.keyCh); 80 85 } 81 86 } … … 96 101 /* Random number. This is a static method, 97 102 not to be used with previous instance */ 98 Console.WriteLine("A random number 103 Console.WriteLine("A random number: {0}", Libcucul.Rand(0, 1337)); 99 104 100 105 dp.EventLoop();
Note: See TracChangeset
for help on using the changeset viewer.