source: libcaca/trunk/csharp/Display.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.1 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 class Display : IDisposable
24    {
25        private Canvas _cv;
26        public Canvas Canvas { get { return _cv; } }
27
28        private IntPtr _c_cv;
29        private IntPtr _c_dp;
30
31        [DllImport("libcaca.dll", CallingConvention=CallingConvention.Cdecl),
32         SuppressUnmanagedCodeSecurity]
33        private static extern IntPtr caca_create_display(IntPtr cv);
34        public Display(Canvas cv)
35        {
36            _cv = cv;
37            _c_cv = _cv._c_cv;
38            _c_dp = caca_create_display(_c_cv);
39        }
40
41        public Display()
42        {
43            /* XXX: we do not call caca_create_display() with a NULL
44             * argument because it's then impossible to create a Canvas
45             * and I don't want to add a weird constructor */
46            _cv = new Canvas();
47            _c_cv = _cv._c_cv;
48            _c_dp = caca_create_display(_c_cv);
49        }
50
51        [DllImport("libcaca.dll", CallingConvention=CallingConvention.Cdecl),
52         SuppressUnmanagedCodeSecurity]
53        private static extern int caca_free_display(IntPtr dp);
54        public void Dispose()
55        {
56            caca_free_display(_c_dp);
57            GC.SuppressFinalize(this);
58        }
59
60        [DllImport("libcaca.dll", CallingConvention=CallingConvention.Cdecl),
61         SuppressUnmanagedCodeSecurity]
62        private static extern int caca_refresh_display(IntPtr dp);
63        public void Refresh()
64        {
65            caca_refresh_display(_c_dp);
66        }
67
68        [DllImport("libcaca.dll", CallingConvention=CallingConvention.Cdecl),
69         SuppressUnmanagedCodeSecurity]
70        private static extern int caca_set_display_time(IntPtr dp, int d);
71        [DllImport("libcaca.dll", CallingConvention=CallingConvention.Cdecl),
72         SuppressUnmanagedCodeSecurity]
73        private static extern int caca_get_display_time(IntPtr dp);
74        public int DisplayTime
75        {
76            get { return caca_get_display_time(_c_dp); }
77            set { caca_set_display_time(_c_dp, value); }
78        }
79
80        [DllImport("libcaca.dll", CallingConvention=CallingConvention.Cdecl),
81         SuppressUnmanagedCodeSecurity]
82        private static extern int caca_get_event(IntPtr dp, uint t,
83                                                 IntPtr cevent,
84                                                 int timeout);
85        public Event getEvent(EventType t, int timeout)
86        {
87            Event e = new Event();
88            caca_get_event(_c_dp, (uint)t, e.cevent, timeout);
89            return e;
90        }
91
92        [DllImport("libcaca.dll", CallingConvention=CallingConvention.Cdecl),
93         SuppressUnmanagedCodeSecurity]
94        private static extern int caca_get_display_width(IntPtr dp);
95        [DllImport("libcaca.dll", CallingConvention=CallingConvention.Cdecl),
96         SuppressUnmanagedCodeSecurity]
97        private static extern int caca_get_display_height(IntPtr dp);
98        public Size Size
99        {
100            get { return new Size(caca_get_display_width(_c_dp),
101                                  caca_get_display_height(_c_dp)); }
102        }
103
104        [DllImport("libcaca.dll", CallingConvention=CallingConvention.Cdecl),
105         SuppressUnmanagedCodeSecurity]
106        private static extern int caca_set_display_title(IntPtr dp, string t);
107        public string Title
108        {
109            set { caca_set_display_title(_c_dp, value); }
110        }
111
112        [DllImport("libcaca.dll", CallingConvention=CallingConvention.Cdecl),
113         SuppressUnmanagedCodeSecurity]
114        private static extern int caca_set_mouse(IntPtr k, bool status);
115        public bool Mouse
116        {
117            set { caca_set_mouse(_c_dp, value); }
118        }
119
120        [DllImport("libcaca.dll", CallingConvention=CallingConvention.Cdecl),
121         SuppressUnmanagedCodeSecurity]
122        private static extern int caca_get_mouse_x(IntPtr k);
123        [DllImport("libcaca.dll", CallingConvention=CallingConvention.Cdecl),
124         SuppressUnmanagedCodeSecurity]
125        private static extern int caca_get_mouse_y(IntPtr k);
126        public Point MousePos
127        {
128            get { return new Point(caca_get_mouse_x(_c_dp),
129                                   caca_get_mouse_y(_c_dp)); }
130        }
131
132        [DllImport("libcaca.dll", CallingConvention=CallingConvention.Cdecl),
133         SuppressUnmanagedCodeSecurity]
134        private static extern int caca_set_cursor(IntPtr k, bool status);
135        public bool Cursor
136        {
137            set { caca_set_cursor(_c_dp, value); }
138        }
139    }
140}
141
Note: See TracBrowser for help on using the repository browser.