source: libcaca/trunk/caca-sharp/Display.cs @ 4333

Last change on this file since 4333 was 4333, checked in by Sam Hocevar, 10 years ago

Large source code cleanup, getting rid of spaces, tabs, and svn keywords.

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