Changeset 2078 for libcaca/trunk/csharp
- Timestamp:
- Nov 27, 2007, 1:58:16 AM (13 years ago)
- Location:
- libcaca/trunk/csharp
- Files:
-
- 4 edited
Legend:
- Unmodified
- Added
- Removed
-
libcaca/trunk/csharp/Caca.cs
r2076 r2078 17 17 using System.Runtime.InteropServices; 18 18 using System.Security; 19 using System.Drawing; 19 20 20 21 using Cucul; … … 113 114 { 114 115 public IntPtr cevent; 115 private IntPtr utf8;116 private IntPtr _utf8; 116 117 117 118 public CacaEvent() 118 119 { 119 120 cevent = Marshal.AllocHGlobal(32); 120 utf8 = Marshal.AllocHGlobal(8);121 _utf8 = Marshal.AllocHGlobal(8); 121 122 } 122 123 … … 124 125 { 125 126 Marshal.FreeHGlobal(cevent); 126 Marshal.FreeHGlobal( utf8);127 Marshal.FreeHGlobal(_utf8); 127 128 GC.SuppressFinalize(this); 128 129 } … … 155 156 SuppressUnmanagedCodeSecurity] 156 157 private static extern int caca_get_event_key_utf8(IntPtr ev, 157 IntPtr utf8);158 IntPtr _utf8); 158 159 public string keyUtf8 159 160 { 160 161 get 161 162 { 162 caca_get_event_key_utf8(cevent, utf8);163 return Marshal.PtrToStringAnsi( utf8);163 caca_get_event_key_utf8(cevent, _utf8); 164 return Marshal.PtrToStringAnsi(_utf8); 164 165 } 165 166 } … … 176 177 SuppressUnmanagedCodeSecurity] 177 178 private static extern int caca_get_event_mouse_x(IntPtr ev); 178 public int mouseX179 {180 get { return caca_get_event_mouse_x(cevent); }181 }182 183 179 [DllImport("libcaca.dll", CallingConvention=CallingConvention.Cdecl), 184 180 SuppressUnmanagedCodeSecurity] 185 181 private static extern int caca_get_event_mouse_y(IntPtr ev); 186 public int mouseY 187 { 188 get { return caca_get_event_mouse_y(cevent); } 182 public Point mousePos 183 { 184 get { return new Point(caca_get_event_mouse_x(cevent), 185 caca_get_event_mouse_y(cevent)); } 189 186 } 190 187 … … 192 189 SuppressUnmanagedCodeSecurity] 193 190 private static extern int caca_get_event_resize_width(IntPtr ev); 194 public int resizeWidth195 {196 get { return caca_get_event_resize_width(cevent); }197 }198 199 191 [DllImport("libcaca.dll", CallingConvention=CallingConvention.Cdecl), 200 192 SuppressUnmanagedCodeSecurity] 201 193 private static extern int caca_get_event_resize_height(IntPtr ev); 202 public int resizeHeight 203 { 204 get { return caca_get_event_resize_height(cevent); } 194 public Size resizeSize 195 { 196 get { return new Size(caca_get_event_resize_width(cevent), 197 caca_get_event_resize_height(cevent)); } 205 198 } 206 199 } … … 264 257 SuppressUnmanagedCodeSecurity] 265 258 private static extern int caca_get_display_width(IntPtr dp); 266 public int width267 {268 get { return caca_get_display_width(_dp); }269 }270 271 259 [DllImport("libcaca.dll", CallingConvention=CallingConvention.Cdecl), 272 260 SuppressUnmanagedCodeSecurity] 273 261 private static extern int caca_get_display_height(IntPtr dp); 274 public int height 275 { 276 get { return caca_get_display_height(_dp); } 262 public Size Size 263 { 264 get { return new Size(caca_get_display_width(_dp), 265 caca_get_display_height(_dp)); } 277 266 } 278 267 … … 296 285 SuppressUnmanagedCodeSecurity] 297 286 private static extern int caca_get_mouse_x(IntPtr k); 298 public int mouseX299 {300 get { return caca_get_mouse_x(_dp); }301 }302 303 287 [DllImport("libcaca.dll", CallingConvention=CallingConvention.Cdecl), 304 288 SuppressUnmanagedCodeSecurity] 305 289 private static extern int caca_get_mouse_y(IntPtr k); 306 public int mouseY 307 { 308 get { return caca_get_mouse_y(_dp); } 290 public Point mousePos 291 { 292 get { return new Point(caca_get_mouse_x(_dp), 293 caca_get_mouse_y(_dp)); } 309 294 } 310 295 … … 318 303 } 319 304 } 305 -
libcaca/trunk/csharp/Cucul.cs
r2076 r2078 17 17 using System.Runtime.InteropServices; 18 18 using System.Security; 19 using System.Drawing; 19 20 20 21 namespace Cucul … … 78 79 } 79 80 80 public CuculCanvas( int w, int h)81 { 82 _cv = cucul_create_canvas( w, h);81 public CuculCanvas(Size s) 82 { 83 _cv = cucul_create_canvas(s.Width, s.Height); 83 84 } 84 85 … … 96 97 private static extern int cucul_set_canvas_size(IntPtr cv, 97 98 int w, int h); 98 public void setSize( int w, int h)99 { 100 cucul_set_canvas_size(_cv, w, h);99 public void setSize(Size s) 100 { 101 cucul_set_canvas_size(_cv, s.Width, s.Height); 101 102 } 102 103 … … 104 105 SuppressUnmanagedCodeSecurity] 105 106 private static extern int cucul_get_canvas_width(IntPtr cv); 106 public int width107 {108 get { return cucul_get_canvas_width(_cv); }109 set { cucul_set_canvas_size(_cv, value,110 cucul_get_canvas_height(_cv)); }111 }112 113 107 [DllImport("libcucul.dll", CallingConvention=CallingConvention.Cdecl), 114 108 SuppressUnmanagedCodeSecurity] 115 109 private static extern int cucul_get_canvas_height(IntPtr cv); 116 public int height 117 { 118 get { return cucul_get_canvas_height(_cv); } 119 set { cucul_set_canvas_size(_cv, cucul_get_canvas_width(_cv), 120 value); } 110 public Size Size 111 { 112 get { return new Size(cucul_get_canvas_width(_cv), 113 cucul_get_canvas_height(_cv)); } 114 set { cucul_set_canvas_size(_cv, value.Width, value.Height); } 115 } 116 117 public Rectangle Rectangle 118 { 119 get { return new Rectangle(0, 0, cucul_get_canvas_width(_cv), 120 cucul_get_canvas_height(_cv)); } 121 set { cucul_set_canvas_size(_cv, value.Width, value.Height); } 121 122 } 122 123 … … 132 133 SuppressUnmanagedCodeSecurity] 133 134 private static extern int cucul_get_cursor_y(IntPtr cv); 134 public int cursorX 135 { 136 get { return cucul_get_cursor_x(_cv); } 137 set { cucul_gotoxy(_cv, value, cucul_get_cursor_y(_cv)); } 138 } 139 140 public int cursorY 141 { 142 get { return cucul_get_cursor_y(_cv); } 143 set { cucul_gotoxy(_cv, cucul_get_cursor_x(_cv), value); } 135 public Point Cursor 136 { 137 get { return new Point(cucul_get_cursor_x(_cv), 138 cucul_get_cursor_y(_cv)); } 139 set { cucul_gotoxy(_cv, value.X, value.Y); } 144 140 } 145 141 … … 148 144 private static extern int cucul_put_char(IntPtr cv, 149 145 int x, int y, int c); 150 public int putChar( int x, int y, int c)151 { 152 return cucul_put_char(_cv, x, y, c);146 public int putChar(Point p, int c) 147 { 148 return cucul_put_char(_cv, p.X, p.Y, c); 153 149 } 154 150 … … 156 152 SuppressUnmanagedCodeSecurity] 157 153 private static extern int cucul_get_char(IntPtr cv, int x, int y); 158 public int getChar( int x, int y)159 { 160 return cucul_get_char(_cv, x, y);154 public int getChar(Point p) 155 { 156 return cucul_get_char(_cv, p.X, p.Y); 161 157 } 162 158 … … 165 161 private static extern int cucul_put_str(IntPtr cv, 166 162 int x, int y, string c); 167 public int putStr( int x, int y, string c)168 { 169 return cucul_put_str(_cv, x, y, c);163 public int putStr(Point p, string c) 164 { 165 return cucul_put_str(_cv, p.X, p.Y, c); 170 166 } 171 167 … … 173 169 SuppressUnmanagedCodeSecurity] 174 170 private static extern int cucul_get_attr(IntPtr cv, int x, int y); 175 public int getAttr( int x, int y)176 { 177 return cucul_get_attr(_cv, x, y);171 public int getAttr(Point p) 172 { 173 return cucul_get_attr(_cv, p.X, p.Y); 178 174 } 179 175 … … 190 186 private static extern int cucul_put_attr(IntPtr cv, 191 187 int x, int y, int a); 192 public int putAttr( int x, int y, int a)193 { 194 return cucul_put_attr(_cv, x, y, a);188 public int putAttr(Point p, int a) 189 { 190 return cucul_put_attr(_cv, p.X, p.Y, a); 195 191 } 196 192 … … 231 227 SuppressUnmanagedCodeSecurity] 232 228 private static extern int cucul_get_canvas_handle_y(IntPtr cv); 233 public int handleX 234 { 235 get { return cucul_get_canvas_handle_x(_cv); } 236 set { cucul_set_canvas_handle(_cv, value, 237 cucul_get_canvas_handle_y(_cv)); } 238 } 239 240 public int handleY 241 { 242 get { return cucul_get_canvas_handle_y(_cv); } 243 set { cucul_set_canvas_handle(_cv, cucul_get_canvas_handle_x(_cv), 244 value); } 229 public Point Handle 230 { 231 get { return new Point(cucul_get_canvas_handle_x(_cv), 232 cucul_get_canvas_handle_y(_cv)); } 233 set { cucul_set_canvas_handle(_cv, value.X, value.Y); } 245 234 } 246 235 … … 249 238 private static extern int cucul_blit(IntPtr cv, int x, int y, 250 239 IntPtr cv1, IntPtr cv2); 251 public int Blit( int x, int y, CuculCanvas canvas)252 { 253 return cucul_blit(_cv, x, y, canvas._cv, IntPtr.Zero);254 } 255 256 public int Blit( int x, int y, CuculCanvas cv, CuculCanvas mask)257 { 258 return cucul_blit(_cv, x, y, cv._cv, mask._cv);240 public int Blit(Point p, CuculCanvas canvas) 241 { 242 return cucul_blit(_cv, p.X, p.Y, canvas._cv, IntPtr.Zero); 243 } 244 245 public int Blit(Point p, CuculCanvas cv, CuculCanvas mask) 246 { 247 return cucul_blit(_cv, p.X, p.Y, cv._cv, mask._cv); 259 248 } 260 249 … … 263 252 private static extern int cucul_set_canvas_boundaries(IntPtr cv, 264 253 int x, int y, 265 int h, int w); 266 public int setBoundaries(int x, int y, int h, int w) 267 { 268 return cucul_set_canvas_boundaries(_cv, x, y, h, w); 254 int h, int w); 255 public int setBoundaries(Rectangle r) 256 { 257 return cucul_set_canvas_boundaries(_cv, r.X, r.Y, 258 r.Width, r.Height); 269 259 } 270 260 … … 340 330 [DllImport("libcucul.dll", CallingConvention=CallingConvention.Cdecl), 341 331 SuppressUnmanagedCodeSecurity] 342 private static extern int cucul_draw_line(IntPtr cv, int x1, int y1, int x2, int y2, int c); 343 public int drawLine(int x1, int y1, int x2, int y2, int c) 344 { 345 return cucul_draw_line(_cv, x1, y1, x2, y2, c); 346 } 332 private static extern int cucul_draw_line(IntPtr cv, int x1, int y1, 333 int x2, int y2, int c); 334 public int drawLine(Point p1, Point p2, int c) 335 { 336 return cucul_draw_line(_cv, p1.X, p1.Y, p2.X, p2.Y, c); 337 } 338 347 339 [DllImport("libcucul.dll", CallingConvention=CallingConvention.Cdecl), 348 340 SuppressUnmanagedCodeSecurity] … … 408 400 int w, int h, 409 401 IntPtr d, IntPtr data); 410 public int ditherBitmap(int x, int y, int w, int h, CuculDither d, 411 object data) 402 public int ditherBitmap(Rectangle r, CuculDither d, object data) 412 403 { 413 404 GCHandle gch = GCHandle.Alloc(data, GCHandleType.Pinned); 414 int ret = cucul_dither_bitmap(_cv, x, y, w, h, d._dither,415 gch.AddrOfPinnedObject());405 int ret = cucul_dither_bitmap(_cv, r.X, r.Y, r.Width, r.Height, 406 d._dither, gch.AddrOfPinnedObject()); 416 407 gch.Free(); 417 408 return ret; … … 465 456 ulong bmask, 466 457 ulong amask); 467 public CuculDither(int bpp, int w,int h, int pitch,458 public CuculDither(int bpp, Size s, int pitch, 468 459 uint rmask, uint gmask, uint bmask, uint amask) 469 460 { 470 _dither = cucul_create_dither(bpp, w, h, pitch,461 _dither = cucul_create_dither(bpp, s.Width, s.Height, pitch, 471 462 rmask, gmask, bmask, amask); 472 463 } -
libcaca/trunk/csharp/Makefile.am
r2072 r2078 18 18 19 19 cucul-sharp.dll: $(cucul_sources) 20 gmcs $(cucul_sources) -out:$@ -target:library -unsafe 20 gmcs -unsafe $(cucul_sources) -out:$@ -target:library \ 21 -r:System.Drawing.dll 21 22 22 23 caca-sharp.dll: $(caca_sources) cucul-sharp.dll 23 gmcs $(caca_sources) -out:$@ -target:library\24 -r:./cucul-sharp.dll -lib:./ -unsafe24 gmcs -unsafe $(caca_sources) -out:$@ -target:library -lib:./ \ 25 -r:System.Drawing.dll -r:./cucul-sharp.dll 25 26 26 27 test.exe: test.cs caca-sharp.dll cucul-sharp.dll 27 gmcs test.cs -out:$@ \28 -r:./cucul-sharp.dll -r:./caca-sharp.dll -lib:./ -unsafe28 gmcs test.cs -out:$@ -lib:./ \ 29 -r:System.Drawing.dll -r:./cucul-sharp.dll -r:./caca-sharp.dll 29 30 30 31 clean-local: -
libcaca/trunk/csharp/test.cs
r2076 r2078 16 16 17 17 using System; 18 using System.Drawing; 18 19 using System.Runtime.InteropServices; 19 20 … … 23 24 class DemoCanvas : CuculCanvas 24 25 { 25 private uint[,] table;26 private uint[,] image; 26 27 27 28 private DateTime startTime; … … 32 33 startTime = DateTime.Now; 33 34 34 table = new uint[16,16]; 35 d = new CuculDither(32, 16, 16, 16 * 4, 0xff0000, 0xff00, 0xff, 0x0); 35 image = new uint[16,16]; 36 d = new CuculDither(32, new Size(16, 16), 16 * 4, 37 0xff0000, 0xff00, 0xff, 0x0); 36 38 } 37 39 … … 56 58 if(y2 < 0) y2 = 0; 57 59 58 table[x,y] = (uint)((x2 + y2) << 16)60 image[x,y] = (uint)((x2 + y2) << 16) 59 61 | (uint)(x2 << 8) 60 62 | (uint)(y2); 61 63 } 62 ditherBitmap( 0, 0, width, height, d, table);64 ditherBitmap(Rectangle, d, image); 63 65 64 66 setColorAnsi(Libcucul.WHITE, Libcucul.BLACK); … … 66 68 { 67 69 double v = ((Math.Sin((t / 500.0) 68 + (i / ((double)barCount))) + 1) / 2) * height; 69 int y = (int)v; 70 + (i / ((double)barCount))) + 1) / 2) * Size.Height; 71 Point p1 = new Point(0, (int)v); 72 Point p2 = new Point(Size.Width - 1, (int)v); 70 73 71 74 setColorAnsi(i + 9, Libcucul.BLACK); 72 75 /* drawLine is already clipped, we don't care about overflows */ 73 drawLine( 0, y - 2, width, y - 2, '-');74 drawLine( 0, y - 1, width, y - 1, '*');75 drawLine( 0, y, width, y,'#');76 drawLine( 0, y + 1, width, y + 1, '*');77 drawLine( 0, y + 2, width, y + 2, '-');76 drawLine(p1 + new Size(0, -2), p2 + new Size(0, -2), '-'); 77 drawLine(p1 + new Size(0, -1), p2 + new Size(0, -1), '*'); 78 drawLine(p1, p2, '#'); 79 drawLine(p1 + new Size(0, 1), p2 + new Size(0, 1), '*'); 80 drawLine(p1 + new Size(0, 2), p2 + new Size(0, 2), '-'); 78 81 } 79 82 80 83 setColorAnsi(Libcucul.WHITE, Libcucul.BLUE); 81 putStr( width - 30, height - 2, " -=[ Powered by libcaca ]=- ");84 putStr(new Point(-30, -2) + Size, " -=[ Powered by libcaca ]=- "); 82 85 setColorAnsi(Libcucul.WHITE, Libcucul.BLACK); 83 86 }
Note: See TracChangeset
for help on using the changeset viewer.