| 1 | /* |
|---|
| 2 | * libcucul .NET bindings for libcucul |
|---|
| 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 | |
|---|
| 16 | using System; |
|---|
| 17 | using System.Runtime.InteropServices; |
|---|
| 18 | using System.Security; |
|---|
| 19 | using System.Drawing; |
|---|
| 20 | |
|---|
| 21 | namespace Cucul |
|---|
| 22 | { |
|---|
| 23 | /* Static libcucul stuff that does not fit in any object */ |
|---|
| 24 | public static class Libcucul |
|---|
| 25 | { |
|---|
| 26 | [DllImport("libcucul.dll", CallingConvention=CallingConvention.Cdecl), |
|---|
| 27 | SuppressUnmanagedCodeSecurity] |
|---|
| 28 | private static extern int cucul_rand(int min, int max); |
|---|
| 29 | public static int Rand(int min, int max) |
|---|
| 30 | { |
|---|
| 31 | return cucul_rand(min, max); |
|---|
| 32 | } |
|---|
| 33 | |
|---|
| 34 | [DllImport("libcucul.dll", CallingConvention=CallingConvention.Cdecl), |
|---|
| 35 | SuppressUnmanagedCodeSecurity] |
|---|
| 36 | private static extern IntPtr cucul_get_version(); |
|---|
| 37 | public static string getVersion() |
|---|
| 38 | { |
|---|
| 39 | return Marshal.PtrToStringAnsi(cucul_get_version()); |
|---|
| 40 | } |
|---|
| 41 | |
|---|
| 42 | public const int BLACK = 0x00, |
|---|
| 43 | BLUE = 0x01, |
|---|
| 44 | GREEN = 0x02, |
|---|
| 45 | CYAN = 0x03, |
|---|
| 46 | RED = 0x04, |
|---|
| 47 | MAGENTA = 0x05, |
|---|
| 48 | BROWN = 0x06, |
|---|
| 49 | LIGHTGRAY = 0x07, |
|---|
| 50 | DARKGRAY = 0x08, |
|---|
| 51 | LIGHTBLUE = 0x09, |
|---|
| 52 | LIGHTGREEN = 0x0a, |
|---|
| 53 | LIGHTCYAN = 0x0b, |
|---|
| 54 | LIGHTRED = 0x0c, |
|---|
| 55 | LIGHTMAGENTA = 0x0d, |
|---|
| 56 | YELLOW = 0x0e, |
|---|
| 57 | WHITE = 0x0f, |
|---|
| 58 | DEFAULT = 0x10, |
|---|
| 59 | TRANSPARENT = 0x20; |
|---|
| 60 | |
|---|
| 61 | public const int BOLD = 0x01, |
|---|
| 62 | ITALICS = 0x02, |
|---|
| 63 | UNDERLINE = 0x04, |
|---|
| 64 | BLINK = 0x08; |
|---|
| 65 | } |
|---|
| 66 | |
|---|
| 67 | public class CuculCanvas : IDisposable |
|---|
| 68 | { |
|---|
| 69 | public readonly IntPtr _c_cv; |
|---|
| 70 | |
|---|
| 71 | /* libcucul basic functions */ |
|---|
| 72 | |
|---|
| 73 | [DllImport("libcucul.dll", CallingConvention=CallingConvention.Cdecl), |
|---|
| 74 | SuppressUnmanagedCodeSecurity] |
|---|
| 75 | private static extern IntPtr cucul_create_canvas(int w, int h); |
|---|
| 76 | public CuculCanvas() |
|---|
| 77 | { |
|---|
| 78 | _c_cv = cucul_create_canvas(0, 0); |
|---|
| 79 | } |
|---|
| 80 | |
|---|
| 81 | public CuculCanvas(Size s) |
|---|
| 82 | { |
|---|
| 83 | _c_cv = cucul_create_canvas(s.Width, s.Height); |
|---|
| 84 | } |
|---|
| 85 | |
|---|
| 86 | public CuculCanvas(int w, int h) |
|---|
| 87 | { |
|---|
| 88 | _c_cv = cucul_create_canvas(h, w); |
|---|
| 89 | } |
|---|
| 90 | |
|---|
| 91 | [DllImport("libcucul.dll", CallingConvention=CallingConvention.Cdecl), |
|---|
| 92 | SuppressUnmanagedCodeSecurity] |
|---|
| 93 | private static extern int cucul_free_canvas(IntPtr cv); |
|---|
| 94 | public void Dispose() |
|---|
| 95 | { |
|---|
| 96 | /* FIXME: don't destroy ourselves if we're attached */ |
|---|
| 97 | cucul_free_canvas(_c_cv); |
|---|
| 98 | GC.SuppressFinalize(this); |
|---|
| 99 | } |
|---|
| 100 | |
|---|
| 101 | [DllImport("libcucul.dll", CallingConvention=CallingConvention.Cdecl), |
|---|
| 102 | SuppressUnmanagedCodeSecurity] |
|---|
| 103 | private static extern int cucul_set_canvas_size(IntPtr cv, |
|---|
| 104 | int w, int h); |
|---|
| 105 | [DllImport("libcucul.dll", CallingConvention=CallingConvention.Cdecl), |
|---|
| 106 | SuppressUnmanagedCodeSecurity] |
|---|
| 107 | private static extern int cucul_get_canvas_width(IntPtr cv); |
|---|
| 108 | [DllImport("libcucul.dll", CallingConvention=CallingConvention.Cdecl), |
|---|
| 109 | SuppressUnmanagedCodeSecurity] |
|---|
| 110 | private static extern int cucul_get_canvas_height(IntPtr cv); |
|---|
| 111 | public Size Size |
|---|
| 112 | { |
|---|
| 113 | get { return new Size(cucul_get_canvas_width(_c_cv), |
|---|
| 114 | cucul_get_canvas_height(_c_cv)); } |
|---|
| 115 | set { cucul_set_canvas_size(_c_cv, value.Width, value.Height); } |
|---|
| 116 | } |
|---|
| 117 | |
|---|
| 118 | public Rectangle Rectangle |
|---|
| 119 | { |
|---|
| 120 | get { return new Rectangle(0, 0, cucul_get_canvas_width(_c_cv), |
|---|
| 121 | cucul_get_canvas_height(_c_cv)); } |
|---|
| 122 | set { cucul_set_canvas_size(_c_cv, value.Width, value.Height); } |
|---|
| 123 | } |
|---|
| 124 | |
|---|
| 125 | /* canvas drawing */ |
|---|
| 126 | |
|---|
| 127 | [DllImport("libcucul.dll", CallingConvention=CallingConvention.Cdecl), |
|---|
| 128 | SuppressUnmanagedCodeSecurity] |
|---|
| 129 | private static extern int cucul_gotoxy(IntPtr cv, int x, int y); |
|---|
| 130 | [DllImport("libcucul.dll", CallingConvention=CallingConvention.Cdecl), |
|---|
| 131 | SuppressUnmanagedCodeSecurity] |
|---|
| 132 | private static extern int cucul_get_cursor_x(IntPtr cv); |
|---|
| 133 | [DllImport("libcucul.dll", CallingConvention=CallingConvention.Cdecl), |
|---|
| 134 | SuppressUnmanagedCodeSecurity] |
|---|
| 135 | private static extern int cucul_get_cursor_y(IntPtr cv); |
|---|
| 136 | public Point Cursor |
|---|
| 137 | { |
|---|
| 138 | get { return new Point(cucul_get_cursor_x(_c_cv), |
|---|
| 139 | cucul_get_cursor_y(_c_cv)); } |
|---|
| 140 | set { cucul_gotoxy(_c_cv, value.X, value.Y); } |
|---|
| 141 | } |
|---|
| 142 | |
|---|
| 143 | [DllImport("libcucul.dll", CallingConvention=CallingConvention.Cdecl), |
|---|
| 144 | SuppressUnmanagedCodeSecurity] |
|---|
| 145 | private static extern int cucul_put_char(IntPtr cv, |
|---|
| 146 | int x, int y, int c); |
|---|
| 147 | public int putChar(Point p, int c) |
|---|
| 148 | { |
|---|
| 149 | return cucul_put_char(_c_cv, p.X, p.Y, c); |
|---|
| 150 | } |
|---|
| 151 | |
|---|
| 152 | public int putChar(int x, int y, int c) |
|---|
| 153 | { |
|---|
| 154 | return cucul_put_char(_c_cv, x, y, c); |
|---|
| 155 | } |
|---|
| 156 | |
|---|
| 157 | [DllImport("libcucul.dll", CallingConvention=CallingConvention.Cdecl), |
|---|
| 158 | SuppressUnmanagedCodeSecurity] |
|---|
| 159 | private static extern int cucul_get_char(IntPtr cv, int x, int y); |
|---|
| 160 | public int getChar(Point p) |
|---|
| 161 | { |
|---|
| 162 | return cucul_get_char(_c_cv, p.X, p.Y); |
|---|
| 163 | } |
|---|
| 164 | |
|---|
| 165 | public int getChar(int x, int y) |
|---|
| 166 | { |
|---|
| 167 | return cucul_get_char(_c_cv, x, y); |
|---|
| 168 | } |
|---|
| 169 | |
|---|
| 170 | [DllImport("libcucul.dll", CallingConvention=CallingConvention.Cdecl), |
|---|
| 171 | SuppressUnmanagedCodeSecurity] |
|---|
| 172 | private static extern int cucul_put_str(IntPtr cv, |
|---|
| 173 | int x, int y, string c); |
|---|
| 174 | public int putStr(Point p, string c) |
|---|
| 175 | { |
|---|
| 176 | return cucul_put_str(_c_cv, p.X, p.Y, c); |
|---|
| 177 | } |
|---|
| 178 | |
|---|
| 179 | public int putStr(int x, int y, string c) |
|---|
| 180 | { |
|---|
| 181 | return cucul_put_str(_c_cv, x, y, c); |
|---|
| 182 | } |
|---|
| 183 | |
|---|
| 184 | [DllImport("libcucul.dll", CallingConvention=CallingConvention.Cdecl), |
|---|
| 185 | SuppressUnmanagedCodeSecurity] |
|---|
| 186 | private static extern int cucul_get_attr(IntPtr cv, int x, int y); |
|---|
| 187 | public int getAttr(Point p) |
|---|
| 188 | { |
|---|
| 189 | return cucul_get_attr(_c_cv, p.X, p.Y); |
|---|
| 190 | } |
|---|
| 191 | |
|---|
| 192 | public int getAttr(int x, int y) |
|---|
| 193 | { |
|---|
| 194 | return cucul_get_attr(_c_cv, x, y); |
|---|
| 195 | } |
|---|
| 196 | |
|---|
| 197 | [DllImport("libcucul.dll", CallingConvention=CallingConvention.Cdecl), |
|---|
| 198 | SuppressUnmanagedCodeSecurity] |
|---|
| 199 | private static extern int cucul_set_attr(IntPtr cv, int a); |
|---|
| 200 | public int setAttr(int a) |
|---|
| 201 | { |
|---|
| 202 | return cucul_set_attr(_c_cv, a); |
|---|
| 203 | } |
|---|
| 204 | |
|---|
| 205 | [DllImport("libcucul.dll", CallingConvention=CallingConvention.Cdecl), |
|---|
| 206 | SuppressUnmanagedCodeSecurity] |
|---|
| 207 | private static extern int cucul_put_attr(IntPtr cv, |
|---|
| 208 | int x, int y, int a); |
|---|
| 209 | public int putAttr(Point p, int a) |
|---|
| 210 | { |
|---|
| 211 | return cucul_put_attr(_c_cv, p.X, p.Y, a); |
|---|
| 212 | } |
|---|
| 213 | |
|---|
| 214 | public int putAttr(int x, int y, int a) |
|---|
| 215 | { |
|---|
| 216 | return cucul_put_attr(_c_cv, x, y, a); |
|---|
| 217 | } |
|---|
| 218 | |
|---|
| 219 | [DllImport("libcucul.dll", CallingConvention=CallingConvention.Cdecl), |
|---|
| 220 | SuppressUnmanagedCodeSecurity] |
|---|
| 221 | private static extern int cucul_set_color_ansi(IntPtr cv, |
|---|
| 222 | byte fg, byte bg); |
|---|
| 223 | public int setColorAnsi(int fg, int bg) |
|---|
| 224 | { |
|---|
| 225 | return cucul_set_color_ansi(_c_cv, (byte)fg, (byte)bg); |
|---|
| 226 | } |
|---|
| 227 | |
|---|
| 228 | [DllImport("libcucul.dll", CallingConvention=CallingConvention.Cdecl), |
|---|
| 229 | SuppressUnmanagedCodeSecurity] |
|---|
| 230 | private static extern int cucul_set_color_argb(IntPtr cv, |
|---|
| 231 | int fg, int bg); |
|---|
| 232 | public int setColorArgb(int fg, int bg) |
|---|
| 233 | { |
|---|
| 234 | return cucul_set_color_argb(_c_cv, fg, bg); |
|---|
| 235 | } |
|---|
| 236 | |
|---|
| 237 | [DllImport("libcucul.dll", CallingConvention=CallingConvention.Cdecl), |
|---|
| 238 | SuppressUnmanagedCodeSecurity] |
|---|
| 239 | private static extern int cucul_clear_canvas(IntPtr cv); |
|---|
| 240 | public int Clear() |
|---|
| 241 | { |
|---|
| 242 | return cucul_clear_canvas(_c_cv); |
|---|
| 243 | } |
|---|
| 244 | |
|---|
| 245 | [DllImport("libcucul.dll", CallingConvention=CallingConvention.Cdecl), |
|---|
| 246 | SuppressUnmanagedCodeSecurity] |
|---|
| 247 | private static extern int cucul_set_canvas_handle(IntPtr cv, |
|---|
| 248 | int x, int y); |
|---|
| 249 | [DllImport("libcucul.dll", CallingConvention=CallingConvention.Cdecl), |
|---|
| 250 | SuppressUnmanagedCodeSecurity] |
|---|
| 251 | private static extern int cucul_get_canvas_handle_x(IntPtr cv); |
|---|
| 252 | [DllImport("libcucul.dll", CallingConvention=CallingConvention.Cdecl), |
|---|
| 253 | SuppressUnmanagedCodeSecurity] |
|---|
| 254 | private static extern int cucul_get_canvas_handle_y(IntPtr cv); |
|---|
| 255 | public Point Handle |
|---|
| 256 | { |
|---|
| 257 | get { return new Point(cucul_get_canvas_handle_x(_c_cv), |
|---|
| 258 | cucul_get_canvas_handle_y(_c_cv)); } |
|---|
| 259 | set { cucul_set_canvas_handle(_c_cv, value.X, value.Y); } |
|---|
| 260 | } |
|---|
| 261 | |
|---|
| 262 | [DllImport("libcucul.dll", CallingConvention=CallingConvention.Cdecl), |
|---|
| 263 | SuppressUnmanagedCodeSecurity] |
|---|
| 264 | private static extern int cucul_blit(IntPtr cv, int x, int y, |
|---|
| 265 | IntPtr cv1, IntPtr cv2); |
|---|
| 266 | public int Blit(Point p, CuculCanvas canvas) |
|---|
| 267 | { |
|---|
| 268 | return cucul_blit(_c_cv, p.X, p.Y, canvas._c_cv, IntPtr.Zero); |
|---|
| 269 | } |
|---|
| 270 | |
|---|
| 271 | public int Blit(Point p, CuculCanvas cv, CuculCanvas mask) |
|---|
| 272 | { |
|---|
| 273 | return cucul_blit(_c_cv, p.X, p.Y, cv._c_cv, mask._c_cv); |
|---|
| 274 | } |
|---|
| 275 | |
|---|
| 276 | public int Blit(int x, int y, CuculCanvas canvas) |
|---|
| 277 | { |
|---|
| 278 | return cucul_blit(_c_cv, x, y, canvas._c_cv, IntPtr.Zero); |
|---|
| 279 | } |
|---|
| 280 | |
|---|
| 281 | public int Blit(int x, int y, CuculCanvas cv, CuculCanvas mask) |
|---|
| 282 | { |
|---|
| 283 | return cucul_blit(_c_cv, x, y, cv._c_cv, mask._c_cv); |
|---|
| 284 | } |
|---|
| 285 | |
|---|
| 286 | [DllImport("libcucul.dll", CallingConvention=CallingConvention.Cdecl), |
|---|
| 287 | SuppressUnmanagedCodeSecurity] |
|---|
| 288 | private static extern int cucul_set_canvas_boundaries(IntPtr cv, |
|---|
| 289 | int x, int y, |
|---|
| 290 | int h, int w); |
|---|
| 291 | public int setBoundaries(Rectangle r) |
|---|
| 292 | { |
|---|
| 293 | return cucul_set_canvas_boundaries(_c_cv, r.X, r.Y, |
|---|
| 294 | r.Width, r.Height); |
|---|
| 295 | } |
|---|
| 296 | |
|---|
| 297 | public int setBoundaries(int x, int y, int w, int h) |
|---|
| 298 | { |
|---|
| 299 | return cucul_set_canvas_boundaries(_c_cv, x, y, w, h); |
|---|
| 300 | } |
|---|
| 301 | |
|---|
| 302 | /* canvas transformation */ |
|---|
| 303 | |
|---|
| 304 | [DllImport("libcucul.dll", CallingConvention=CallingConvention.Cdecl), |
|---|
| 305 | SuppressUnmanagedCodeSecurity] |
|---|
| 306 | private static extern int cucul_invert(IntPtr cv); |
|---|
| 307 | public int Invert() |
|---|
| 308 | { |
|---|
| 309 | return cucul_invert(_c_cv); |
|---|
| 310 | } |
|---|
| 311 | |
|---|
| 312 | [DllImport("libcucul.dll", CallingConvention=CallingConvention.Cdecl), |
|---|
| 313 | SuppressUnmanagedCodeSecurity] |
|---|
| 314 | private static extern int cucul_flip(IntPtr cv); |
|---|
| 315 | public int Flip() |
|---|
| 316 | { |
|---|
| 317 | return cucul_flip(_c_cv); |
|---|
| 318 | } |
|---|
| 319 | |
|---|
| 320 | [DllImport("libcucul.dll", CallingConvention=CallingConvention.Cdecl), |
|---|
| 321 | SuppressUnmanagedCodeSecurity] |
|---|
| 322 | private static extern int cucul_flop(IntPtr cv); |
|---|
| 323 | public int Flop() |
|---|
| 324 | { |
|---|
| 325 | return cucul_flop(_c_cv); |
|---|
| 326 | } |
|---|
| 327 | |
|---|
| 328 | [DllImport("libcucul.dll", CallingConvention=CallingConvention.Cdecl), |
|---|
| 329 | SuppressUnmanagedCodeSecurity] |
|---|
| 330 | private static extern int cucul_rotate_180(IntPtr cv); |
|---|
| 331 | public int Rotate180() |
|---|
| 332 | { |
|---|
| 333 | return cucul_rotate_180(_c_cv); |
|---|
| 334 | } |
|---|
| 335 | |
|---|
| 336 | [DllImport("libcucul.dll", CallingConvention=CallingConvention.Cdecl), |
|---|
| 337 | SuppressUnmanagedCodeSecurity] |
|---|
| 338 | private static extern int cucul_rotate_left(IntPtr cv); |
|---|
| 339 | public int RotateLeft() |
|---|
| 340 | { |
|---|
| 341 | return cucul_rotate_left(_c_cv); |
|---|
| 342 | } |
|---|
| 343 | |
|---|
| 344 | [DllImport("libcucul.dll", CallingConvention=CallingConvention.Cdecl), |
|---|
| 345 | SuppressUnmanagedCodeSecurity] |
|---|
| 346 | private static extern int cucul_rotate_right(IntPtr cv); |
|---|
| 347 | public int RotateRight() |
|---|
| 348 | { |
|---|
| 349 | return cucul_rotate_right(_c_cv); |
|---|
| 350 | } |
|---|
| 351 | |
|---|
| 352 | [DllImport("libcucul.dll", CallingConvention=CallingConvention.Cdecl), |
|---|
| 353 | SuppressUnmanagedCodeSecurity] |
|---|
| 354 | private static extern int cucul_stretch_left(IntPtr cv); |
|---|
| 355 | public int StretchLeft() |
|---|
| 356 | { |
|---|
| 357 | return cucul_stretch_left(_c_cv); |
|---|
| 358 | } |
|---|
| 359 | |
|---|
| 360 | [DllImport("libcucul.dll", CallingConvention=CallingConvention.Cdecl), |
|---|
| 361 | SuppressUnmanagedCodeSecurity] |
|---|
| 362 | private static extern int cucul_stretch_right(IntPtr cv); |
|---|
| 363 | public int StretchRight() |
|---|
| 364 | { |
|---|
| 365 | return cucul_stretch_right(_c_cv); |
|---|
| 366 | } |
|---|
| 367 | |
|---|
| 368 | /* primitives drawing */ |
|---|
| 369 | |
|---|
| 370 | [DllImport("libcucul.dll", CallingConvention=CallingConvention.Cdecl), |
|---|
| 371 | SuppressUnmanagedCodeSecurity] |
|---|
| 372 | private static extern int cucul_draw_line(IntPtr cv, int x1, int y1, |
|---|
| 373 | int x2, int y2, uint c); |
|---|
| 374 | public int drawLine(Point p1, Point p2, uint c) |
|---|
| 375 | { |
|---|
| 376 | return cucul_draw_line(_c_cv, p1.X, p1.Y, p2.X, p2.Y, c); |
|---|
| 377 | } |
|---|
| 378 | |
|---|
| 379 | public int drawLine(int x1, int y1, int x2, int y2, uint c) |
|---|
| 380 | { |
|---|
| 381 | return cucul_draw_line(_c_cv, x1, y1, x2, y2, c); |
|---|
| 382 | } |
|---|
| 383 | |
|---|
| 384 | [DllImport("libcucul.dll", CallingConvention=CallingConvention.Cdecl), |
|---|
| 385 | SuppressUnmanagedCodeSecurity] |
|---|
| 386 | private static extern int cucul_draw_polyline(IntPtr cv, int[] x, |
|---|
| 387 | int[] y, int n, uint c); |
|---|
| 388 | public int drawPolyline(Point[] lp, uint c) |
|---|
| 389 | { |
|---|
| 390 | int[] lx = new int[lp.Length]; |
|---|
| 391 | int[] ly = new int[lp.Length]; |
|---|
| 392 | for(int i = 0; i < lp.Length; i++) |
|---|
| 393 | { |
|---|
| 394 | lx[i] = lp[i].X; |
|---|
| 395 | ly[i] = lp[i].Y; |
|---|
| 396 | } |
|---|
| 397 | return cucul_draw_polyline(_c_cv, lx, ly, lp.Length - 1, c); |
|---|
| 398 | } |
|---|
| 399 | |
|---|
| 400 | public int drawPolyline(int[] lx, int[] ly, uint c) |
|---|
| 401 | { |
|---|
| 402 | if(lx.Length != ly.Length) |
|---|
| 403 | return -1; |
|---|
| 404 | |
|---|
| 405 | return cucul_draw_polyline(_c_cv, lx, ly, lx.Length - 1, c); |
|---|
| 406 | } |
|---|
| 407 | |
|---|
| 408 | [DllImport("libcucul.dll", CallingConvention=CallingConvention.Cdecl), |
|---|
| 409 | SuppressUnmanagedCodeSecurity] |
|---|
| 410 | private static extern int cucul_draw_thin_line(IntPtr cv, int x1, |
|---|
| 411 | int y1, int x2, int y2); |
|---|
| 412 | public int drawThinLine(Point p1, Point p2) |
|---|
| 413 | { |
|---|
| 414 | return cucul_draw_thin_line(_c_cv, p1.X, p1.Y, p2.X, p2.Y); |
|---|
| 415 | } |
|---|
| 416 | |
|---|
| 417 | public int drawThinLine(int x1, int y1, int x2, int y2) |
|---|
| 418 | { |
|---|
| 419 | return cucul_draw_thin_line(_c_cv, x1, y1, x2, y2); |
|---|
| 420 | } |
|---|
| 421 | |
|---|
| 422 | [DllImport("libcucul.dll", CallingConvention=CallingConvention.Cdecl), |
|---|
| 423 | SuppressUnmanagedCodeSecurity] |
|---|
| 424 | private static extern int cucul_draw_thin_polyline(IntPtr cv, int[] x, |
|---|
| 425 | int[] y, int n); |
|---|
| 426 | public int drawThinPolyline(Point[] lp) |
|---|
| 427 | { |
|---|
| 428 | int[] lx = new int[lp.Length]; |
|---|
| 429 | int[] ly = new int[lp.Length]; |
|---|
| 430 | for(int i = 0; i < lp.Length; i++) |
|---|
| 431 | { |
|---|
| 432 | lx[i] = lp[i].X; |
|---|
| 433 | ly[i] = lp[i].Y; |
|---|
| 434 | } |
|---|
| 435 | return cucul_draw_thin_polyline(_c_cv, lx, ly, lp.Length - 1); |
|---|
| 436 | } |
|---|
| 437 | |
|---|
| 438 | public int drawThinPolyline(int[] lx, int[] ly) |
|---|
| 439 | { |
|---|
| 440 | if(lx.Length != ly.Length) |
|---|
| 441 | return -1; |
|---|
| 442 | |
|---|
| 443 | return cucul_draw_thin_polyline(_c_cv, lx, ly, lx.Length - 1); |
|---|
| 444 | } |
|---|
| 445 | |
|---|
| 446 | [DllImport("libcucul.dll", CallingConvention=CallingConvention.Cdecl), |
|---|
| 447 | SuppressUnmanagedCodeSecurity] |
|---|
| 448 | private static extern int cucul_draw_circle(IntPtr cv, int x, int y, |
|---|
| 449 | int r, uint c); |
|---|
| 450 | public int drawCircle(Point p, int r, uint c) |
|---|
| 451 | { |
|---|
| 452 | return cucul_draw_circle(_c_cv, p.X, p.Y, r, c); |
|---|
| 453 | } |
|---|
| 454 | |
|---|
| 455 | public int drawCircle(int x, int y, int r, uint c) |
|---|
| 456 | { |
|---|
| 457 | return cucul_draw_circle(_c_cv, x, y, r, c); |
|---|
| 458 | } |
|---|
| 459 | |
|---|
| 460 | [DllImport("libcucul.dll", CallingConvention=CallingConvention.Cdecl), |
|---|
| 461 | SuppressUnmanagedCodeSecurity] |
|---|
| 462 | private static extern int cucul_draw_ellipse(IntPtr cv, int x, int y, |
|---|
| 463 | int a, int b, uint c); |
|---|
| 464 | public int drawEllipse(Point p, int a, int b, uint c) |
|---|
| 465 | { |
|---|
| 466 | return cucul_draw_ellipse(_c_cv, p.X, p.Y, a, b, c); |
|---|
| 467 | } |
|---|
| 468 | |
|---|
| 469 | public int drawEllipse(int x, int y, int a, int b, uint c) |
|---|
| 470 | { |
|---|
| 471 | return cucul_draw_ellipse(_c_cv, x, y, a, b, c); |
|---|
| 472 | } |
|---|
| 473 | |
|---|
| 474 | [DllImport("libcucul.dll", CallingConvention=CallingConvention.Cdecl), |
|---|
| 475 | SuppressUnmanagedCodeSecurity] |
|---|
| 476 | private static extern int cucul_draw_thin_ellipse(IntPtr cv, |
|---|
| 477 | int x, int y, |
|---|
| 478 | int a, int b); |
|---|
| 479 | public int drawThinEllipse(Point p, int a, int b) |
|---|
| 480 | { |
|---|
| 481 | return cucul_draw_thin_ellipse(_c_cv, p.X, p.Y, a, b); |
|---|
| 482 | } |
|---|
| 483 | |
|---|
| 484 | public int drawThinEllipse(int x, int y, int a, int b) |
|---|
| 485 | { |
|---|
| 486 | return cucul_draw_thin_ellipse(_c_cv, x, y, a, b); |
|---|
| 487 | } |
|---|
| 488 | |
|---|
| 489 | [DllImport("libcucul.dll", CallingConvention=CallingConvention.Cdecl), |
|---|
| 490 | SuppressUnmanagedCodeSecurity] |
|---|
| 491 | private static extern int cucul_fill_ellipse(IntPtr cv, int x, int y, |
|---|
| 492 | int a, int b, uint c); |
|---|
| 493 | public int fillEllipse(Point p, int a, int b, uint c) |
|---|
| 494 | { |
|---|
| 495 | return cucul_fill_ellipse(_c_cv, p.X, p.Y, a, b, c); |
|---|
| 496 | } |
|---|
| 497 | |
|---|
| 498 | public int fillEllipse(int x, int y, int a, int b, uint c) |
|---|
| 499 | { |
|---|
| 500 | return cucul_fill_ellipse(_c_cv, x, y, a, b, c); |
|---|
| 501 | } |
|---|
| 502 | |
|---|
| 503 | [DllImport("libcucul.dll", CallingConvention=CallingConvention.Cdecl), |
|---|
| 504 | SuppressUnmanagedCodeSecurity] |
|---|
| 505 | private static extern int cucul_draw_box(IntPtr cv, int x, int y, |
|---|
| 506 | int w, int h, uint c); |
|---|
| 507 | public int drawBox(Rectangle r, uint c) |
|---|
| 508 | { |
|---|
| 509 | return cucul_draw_box(_c_cv, r.X, r.Y, r.Width, r.Height, c); |
|---|
| 510 | } |
|---|
| 511 | |
|---|
| 512 | public int drawBox(int x, int y, int w, int h, uint c) |
|---|
| 513 | { |
|---|
| 514 | return cucul_draw_box(_c_cv, x, y, w, h, c); |
|---|
| 515 | } |
|---|
| 516 | |
|---|
| 517 | [DllImport("libcucul.dll", CallingConvention=CallingConvention.Cdecl), |
|---|
| 518 | SuppressUnmanagedCodeSecurity] |
|---|
| 519 | private static extern int cucul_draw_thin_box(IntPtr cv, int x, int y, |
|---|
| 520 | int w, int h); |
|---|
| 521 | public int drawThinBox(Rectangle r) |
|---|
| 522 | { |
|---|
| 523 | return cucul_draw_thin_box(_c_cv, r.X, r.Y, r.Width, r.Height); |
|---|
| 524 | } |
|---|
| 525 | |
|---|
| 526 | public int drawThinBox(int x, int y, int w, int h) |
|---|
| 527 | { |
|---|
| 528 | return cucul_draw_thin_box(_c_cv, x, y, w, h); |
|---|
| 529 | } |
|---|
| 530 | |
|---|
| 531 | [DllImport("libcucul.dll", CallingConvention=CallingConvention.Cdecl), |
|---|
| 532 | SuppressUnmanagedCodeSecurity] |
|---|
| 533 | private static extern int cucul_draw_cp437_box(IntPtr cv, int x, int y, |
|---|
| 534 | int w, int h); |
|---|
| 535 | public int drawCp437Box(Rectangle r) |
|---|
| 536 | { |
|---|
| 537 | return cucul_draw_cp437_box(_c_cv, r.X, r.Y, r.Width, r.Height); |
|---|
| 538 | } |
|---|
| 539 | |
|---|
| 540 | public int drawCp437Box(int x, int y, int w, int h) |
|---|
| 541 | { |
|---|
| 542 | return cucul_draw_cp437_box(_c_cv, x, y, w, h); |
|---|
| 543 | } |
|---|
| 544 | |
|---|
| 545 | [DllImport("libcucul.dll", CallingConvention=CallingConvention.Cdecl), |
|---|
| 546 | SuppressUnmanagedCodeSecurity] |
|---|
| 547 | private static extern int cucul_fill_box(IntPtr cv, int x, int y, |
|---|
| 548 | int w, int h, uint c); |
|---|
| 549 | public int fillBox(Rectangle r, uint c) |
|---|
| 550 | { |
|---|
| 551 | return cucul_fill_box(_c_cv, r.X, r.Y, r.Width, r.Height, c); |
|---|
| 552 | } |
|---|
| 553 | |
|---|
| 554 | public int fillBox(int x, int y, int w, int h, uint c) |
|---|
| 555 | { |
|---|
| 556 | return cucul_fill_box(_c_cv, x, y, w, h, c); |
|---|
| 557 | } |
|---|
| 558 | |
|---|
| 559 | [DllImport("libcucul.dll", CallingConvention=CallingConvention.Cdecl), |
|---|
| 560 | SuppressUnmanagedCodeSecurity] |
|---|
| 561 | private static extern int cucul_draw_triangle(IntPtr cv, int x1, |
|---|
| 562 | int y1, int x2, int y2, |
|---|
| 563 | int x3, int y3, uint c); |
|---|
| 564 | public int drawTriangle(Point p1, Point p2, Point p3, uint c) |
|---|
| 565 | { |
|---|
| 566 | return cucul_draw_triangle(_c_cv, p1.X, p1.Y, p2.X, p2.Y, |
|---|
| 567 | p3.X, p3.Y, c); |
|---|
| 568 | } |
|---|
| 569 | |
|---|
| 570 | public int drawTriangle(int x1, int y1, int x2, int y2, |
|---|
| 571 | int x3, int y3, uint c) |
|---|
| 572 | { |
|---|
| 573 | return cucul_draw_triangle(_c_cv, x1, y1, x2, y2, x3, y3, c); |
|---|
| 574 | } |
|---|
| 575 | |
|---|
| 576 | [DllImport("libcucul.dll", CallingConvention=CallingConvention.Cdecl), |
|---|
| 577 | SuppressUnmanagedCodeSecurity] |
|---|
| 578 | private static extern int cucul_draw_thin_triangle(IntPtr cv, |
|---|
| 579 | int x1, int y1, |
|---|
| 580 | int x2, int y2, |
|---|
| 581 | int x3, int y3); |
|---|
| 582 | public int drawThinTriangle(Point p1, Point p2, Point p3) |
|---|
| 583 | { |
|---|
| 584 | return cucul_draw_thin_triangle(_c_cv, p1.X, p1.Y, p2.X, p2.Y, |
|---|
| 585 | p3.X, p3.Y); |
|---|
| 586 | } |
|---|
| 587 | |
|---|
| 588 | public int drawThinTriangle(int x1, int y1, int x2, int y2, |
|---|
| 589 | int x3, int y3) |
|---|
| 590 | { |
|---|
| 591 | return cucul_draw_thin_triangle(_c_cv, x1, y1, x2, y2, x3, y3); |
|---|
| 592 | } |
|---|
| 593 | |
|---|
| 594 | [DllImport("libcucul.dll", CallingConvention=CallingConvention.Cdecl), |
|---|
| 595 | SuppressUnmanagedCodeSecurity] |
|---|
| 596 | private static extern int cucul_fill_triangle(IntPtr cv, int x1, |
|---|
| 597 | int y1, int x2, int y2, |
|---|
| 598 | int x3, int y3, uint c); |
|---|
| 599 | public int fillTriangle(Point p1, Point p2, Point p3, uint c) |
|---|
| 600 | { |
|---|
| 601 | return cucul_fill_triangle(_c_cv, p1.X, p1.Y, p2.X, p2.Y, |
|---|
| 602 | p3.X, p3.Y, c); |
|---|
| 603 | } |
|---|
| 604 | |
|---|
| 605 | public int fillTriangle(int x1, int y1, int x2, int y2, |
|---|
| 606 | int x3, int y3, uint c) |
|---|
| 607 | { |
|---|
| 608 | return cucul_fill_triangle(_c_cv, x1, y1, x2, y2, x3, y3, c); |
|---|
| 609 | } |
|---|
| 610 | |
|---|
| 611 | /* frame handling */ |
|---|
| 612 | |
|---|
| 613 | [DllImport("libcucul.dll", CallingConvention=CallingConvention.Cdecl), |
|---|
| 614 | SuppressUnmanagedCodeSecurity] |
|---|
| 615 | private static extern int cucul_get_frame_count(IntPtr cv); |
|---|
| 616 | public int getFrameCount() |
|---|
| 617 | { |
|---|
| 618 | return cucul_get_frame_count(_c_cv); |
|---|
| 619 | } |
|---|
| 620 | |
|---|
| 621 | [DllImport("libcucul.dll", CallingConvention=CallingConvention.Cdecl), |
|---|
| 622 | SuppressUnmanagedCodeSecurity] |
|---|
| 623 | private static extern int cucul_set_frame(IntPtr cv, int f); |
|---|
| 624 | public int setFrame(int f) |
|---|
| 625 | { |
|---|
| 626 | return cucul_set_frame(_c_cv, f); |
|---|
| 627 | } |
|---|
| 628 | |
|---|
| 629 | [DllImport("libcucul.dll", CallingConvention=CallingConvention.Cdecl), |
|---|
| 630 | SuppressUnmanagedCodeSecurity] |
|---|
| 631 | private static extern string cucul_get_frame_name(IntPtr cv); |
|---|
| 632 | [DllImport("libcucul.dll", CallingConvention=CallingConvention.Cdecl), |
|---|
| 633 | SuppressUnmanagedCodeSecurity] |
|---|
| 634 | private static extern int cucul_set_frame_name(IntPtr cv, string n); |
|---|
| 635 | public string FrameName |
|---|
| 636 | { |
|---|
| 637 | get { return cucul_get_frame_name(_c_cv); } |
|---|
| 638 | set { cucul_set_frame_name(_c_cv, value); } |
|---|
| 639 | } |
|---|
| 640 | |
|---|
| 641 | [DllImport("libcucul.dll", CallingConvention=CallingConvention.Cdecl), |
|---|
| 642 | SuppressUnmanagedCodeSecurity] |
|---|
| 643 | private static extern int cucul_create_frame(IntPtr cv, int f); |
|---|
| 644 | public int createFrame(int f) |
|---|
| 645 | { |
|---|
| 646 | return cucul_create_frame(_c_cv, f); |
|---|
| 647 | } |
|---|
| 648 | |
|---|
| 649 | [DllImport("libcucul.dll", CallingConvention=CallingConvention.Cdecl), |
|---|
| 650 | SuppressUnmanagedCodeSecurity] |
|---|
| 651 | private static extern int cucul_free_frame(IntPtr cv, int f); |
|---|
| 652 | public int freeFrame(int f) |
|---|
| 653 | { |
|---|
| 654 | return cucul_free_frame(_c_cv, f); |
|---|
| 655 | } |
|---|
| 656 | |
|---|
| 657 | /* bitmap dithering */ |
|---|
| 658 | |
|---|
| 659 | [DllImport("libcucul.dll", CallingConvention=CallingConvention.Cdecl), |
|---|
| 660 | SuppressUnmanagedCodeSecurity] |
|---|
| 661 | private static extern int cucul_dither_bitmap(IntPtr c, int x, int y, |
|---|
| 662 | int w, int h, |
|---|
| 663 | IntPtr d, IntPtr data); |
|---|
| 664 | public int ditherBitmap(Rectangle r, CuculDither d, object data) |
|---|
| 665 | { |
|---|
| 666 | GCHandle gch = GCHandle.Alloc(data, GCHandleType.Pinned); |
|---|
| 667 | int ret = cucul_dither_bitmap(_c_cv, r.X, r.Y, r.Width, r.Height, |
|---|
| 668 | d._dither, gch.AddrOfPinnedObject()); |
|---|
| 669 | gch.Free(); |
|---|
| 670 | return ret; |
|---|
| 671 | } |
|---|
| 672 | |
|---|
| 673 | public int ditherBitmap(int x, int y, int w, int h, |
|---|
| 674 | CuculDither d, object data) |
|---|
| 675 | { |
|---|
| 676 | GCHandle gch = GCHandle.Alloc(data, GCHandleType.Pinned); |
|---|
| 677 | int ret = cucul_dither_bitmap(_c_cv, x, y, w, h, d._dither, |
|---|
| 678 | gch.AddrOfPinnedObject()); |
|---|
| 679 | gch.Free(); |
|---|
| 680 | return ret; |
|---|
| 681 | } |
|---|
| 682 | } |
|---|
| 683 | |
|---|
| 684 | public class CuculAttr |
|---|
| 685 | { |
|---|
| 686 | private int _attr; |
|---|
| 687 | |
|---|
| 688 | public CuculAttr(int attr) |
|---|
| 689 | { |
|---|
| 690 | _attr = attr; |
|---|
| 691 | } |
|---|
| 692 | |
|---|
| 693 | [DllImport("libcucul.dll", CallingConvention=CallingConvention.Cdecl), |
|---|
| 694 | SuppressUnmanagedCodeSecurity] |
|---|
| 695 | private static extern byte cucul_attr_to_ansi(Int32 a); |
|---|
| 696 | public byte toAnsi() |
|---|
| 697 | { |
|---|
| 698 | return cucul_attr_to_ansi(_attr); |
|---|
| 699 | } |
|---|
| 700 | |
|---|
| 701 | [DllImport("libcucul.dll", CallingConvention=CallingConvention.Cdecl), |
|---|
| 702 | SuppressUnmanagedCodeSecurity] |
|---|
| 703 | private static extern byte cucul_attr_to_ansi_fg(Int32 a); |
|---|
| 704 | public byte toAnsiFg() |
|---|
| 705 | { |
|---|
| 706 | return cucul_attr_to_ansi_fg(_attr); |
|---|
| 707 | } |
|---|
| 708 | |
|---|
| 709 | [DllImport("libcucul.dll", CallingConvention=CallingConvention.Cdecl), |
|---|
| 710 | SuppressUnmanagedCodeSecurity] |
|---|
| 711 | private static extern byte cucul_attr_to_ansi_bg(Int32 a); |
|---|
| 712 | public byte toAnsiBg() |
|---|
| 713 | { |
|---|
| 714 | return cucul_attr_to_ansi_bg(_attr); |
|---|
| 715 | } |
|---|
| 716 | } |
|---|
| 717 | |
|---|
| 718 | public class CuculDither : IDisposable |
|---|
| 719 | { |
|---|
| 720 | public readonly IntPtr _dither; |
|---|
| 721 | |
|---|
| 722 | [DllImport("libcucul.dll", CallingConvention=CallingConvention.Cdecl), |
|---|
| 723 | SuppressUnmanagedCodeSecurity] |
|---|
| 724 | private static extern IntPtr cucul_create_dither(int bpp, int w, |
|---|
| 725 | int h, int pitch, |
|---|
| 726 | ulong rmask, |
|---|
| 727 | ulong gmask, |
|---|
| 728 | ulong bmask, |
|---|
| 729 | ulong amask); |
|---|
| 730 | public CuculDither(int bpp, Size s, int pitch, |
|---|
| 731 | uint rmask, uint gmask, uint bmask, uint amask) |
|---|
| 732 | { |
|---|
| 733 | _dither = cucul_create_dither(bpp, s.Width, s.Height, pitch, |
|---|
| 734 | rmask, gmask, bmask, amask); |
|---|
| 735 | } |
|---|
| 736 | |
|---|
| 737 | [DllImport("libcucul.dll", CallingConvention=CallingConvention.Cdecl), |
|---|
| 738 | SuppressUnmanagedCodeSecurity] |
|---|
| 739 | private static extern int cucul_free_dither(IntPtr d); |
|---|
| 740 | public void Dispose() |
|---|
| 741 | { |
|---|
| 742 | cucul_free_dither(_dither); |
|---|
| 743 | GC.SuppressFinalize(this); |
|---|
| 744 | } |
|---|
| 745 | |
|---|
| 746 | /* TODO: fix this shit */ |
|---|
| 747 | |
|---|
| 748 | [DllImport("libcucul.dll", CallingConvention=CallingConvention.Cdecl), |
|---|
| 749 | SuppressUnmanagedCodeSecurity] |
|---|
| 750 | private static extern int cucul_set_dither_palette(IntPtr d, |
|---|
| 751 | int[] r, int[] g, |
|---|
| 752 | int[] b, int[] a); |
|---|
| 753 | [DllImport("libcucul.dll", CallingConvention=CallingConvention.Cdecl), |
|---|
| 754 | SuppressUnmanagedCodeSecurity] |
|---|
| 755 | private static extern int cucul_set_dither_brightness(IntPtr d, float b); |
|---|
| 756 | [DllImport("libcucul.dll", CallingConvention=CallingConvention.Cdecl), |
|---|
| 757 | SuppressUnmanagedCodeSecurity] |
|---|
| 758 | private static extern int cucul_set_dither_gamma(IntPtr d, float g); |
|---|
| 759 | [DllImport("libcucul.dll", CallingConvention=CallingConvention.Cdecl), |
|---|
| 760 | SuppressUnmanagedCodeSecurity] |
|---|
| 761 | private static extern int cucul_set_dither_contrast(IntPtr d, float c); |
|---|
| 762 | [DllImport("libcucul.dll", CallingConvention=CallingConvention.Cdecl), |
|---|
| 763 | SuppressUnmanagedCodeSecurity] |
|---|
| 764 | private static extern int cucul_set_dither_invert(IntPtr d, int i); |
|---|
| 765 | [DllImport("libcucul.dll", CallingConvention=CallingConvention.Cdecl), |
|---|
| 766 | SuppressUnmanagedCodeSecurity] |
|---|
| 767 | private static extern int cucul_set_dither_antialias(IntPtr d, string s); |
|---|
| 768 | [DllImport("libcucul.dll", CallingConvention=CallingConvention.Cdecl), |
|---|
| 769 | SuppressUnmanagedCodeSecurity] |
|---|
| 770 | private static extern string[] cucul_get_dither_antialias_list(IntPtr d); |
|---|
| 771 | [DllImport("libcucul.dll", CallingConvention=CallingConvention.Cdecl), |
|---|
| 772 | SuppressUnmanagedCodeSecurity] |
|---|
| 773 | private static extern int cucul_set_dither_color(IntPtr d, string s); |
|---|
| 774 | [DllImport("libcucul.dll", CallingConvention=CallingConvention.Cdecl), |
|---|
| 775 | SuppressUnmanagedCodeSecurity] |
|---|
| 776 | private static extern string[] cucul_get_dither_color_list(IntPtr d); |
|---|
| 777 | [DllImport("libcucul.dll", CallingConvention=CallingConvention.Cdecl), |
|---|
| 778 | SuppressUnmanagedCodeSecurity] |
|---|
| 779 | private static extern int cucul_set_dither_charset(IntPtr d, string s); |
|---|
| 780 | [DllImport("libcucul.dll", CallingConvention=CallingConvention.Cdecl), |
|---|
| 781 | SuppressUnmanagedCodeSecurity] |
|---|
| 782 | private static extern string[] cucul_get_dither_charset_list(IntPtr d); |
|---|
| 783 | [DllImport("libcucul.dll", CallingConvention=CallingConvention.Cdecl), |
|---|
| 784 | SuppressUnmanagedCodeSecurity] |
|---|
| 785 | private static extern int cucul_set_dither_mode(IntPtr d, string s); |
|---|
| 786 | [DllImport("libcucul.dll", CallingConvention=CallingConvention.Cdecl), |
|---|
| 787 | SuppressUnmanagedCodeSecurity] |
|---|
| 788 | private static extern string[] cucul_get_dither_mode_list(IntPtr d); |
|---|
| 789 | |
|---|
| 790 | |
|---|
| 791 | public int setBrightness(float b) |
|---|
| 792 | { |
|---|
| 793 | return cucul_set_dither_brightness(_dither, b); |
|---|
| 794 | } |
|---|
| 795 | |
|---|
| 796 | public int setGamma(float g) |
|---|
| 797 | { |
|---|
| 798 | return cucul_set_dither_gamma(_dither, g); |
|---|
| 799 | } |
|---|
| 800 | |
|---|
| 801 | public int setContrast(float c) |
|---|
| 802 | { |
|---|
| 803 | return cucul_set_dither_contrast(_dither, c); |
|---|
| 804 | } |
|---|
| 805 | |
|---|
| 806 | public int setInvert(int i) |
|---|
| 807 | { |
|---|
| 808 | return cucul_set_dither_invert(_dither, i); |
|---|
| 809 | } |
|---|
| 810 | |
|---|
| 811 | public int setAntialias(string s) |
|---|
| 812 | { |
|---|
| 813 | return cucul_set_dither_antialias(_dither, s); |
|---|
| 814 | } |
|---|
| 815 | |
|---|
| 816 | public int setColor(string s) |
|---|
| 817 | { |
|---|
| 818 | return cucul_set_dither_color(_dither, s); |
|---|
| 819 | } |
|---|
| 820 | |
|---|
| 821 | public int setCharset(string s) |
|---|
| 822 | { |
|---|
| 823 | return cucul_set_dither_charset(_dither, s); |
|---|
| 824 | } |
|---|
| 825 | |
|---|
| 826 | public int setMode(string s) |
|---|
| 827 | { |
|---|
| 828 | return cucul_set_dither_mode(_dither, s); |
|---|
| 829 | } |
|---|
| 830 | |
|---|
| 831 | /* <FIXME> */ |
|---|
| 832 | public string[] getAntialiasList() |
|---|
| 833 | { |
|---|
| 834 | return cucul_get_dither_antialias_list(_dither); |
|---|
| 835 | } |
|---|
| 836 | |
|---|
| 837 | public string[] getColorList() |
|---|
| 838 | { |
|---|
| 839 | return cucul_get_dither_color_list(_dither); |
|---|
| 840 | } |
|---|
| 841 | |
|---|
| 842 | public string[] getCharsetList() |
|---|
| 843 | { |
|---|
| 844 | return cucul_get_dither_charset_list(_dither); |
|---|
| 845 | } |
|---|
| 846 | |
|---|
| 847 | public string[] getModeList() |
|---|
| 848 | { |
|---|
| 849 | return cucul_get_dither_mode_list(_dither); |
|---|
| 850 | } |
|---|
| 851 | |
|---|
| 852 | /* </FIXME> */ |
|---|
| 853 | } |
|---|
| 854 | |
|---|
| 855 | public class CuculFont : IDisposable |
|---|
| 856 | { |
|---|
| 857 | private IntPtr _font; |
|---|
| 858 | private GCHandle _gch; |
|---|
| 859 | |
|---|
| 860 | [DllImport("libcucul.dll", CallingConvention=CallingConvention.Cdecl), |
|---|
| 861 | SuppressUnmanagedCodeSecurity] |
|---|
| 862 | private static extern IntPtr cucul_load_font(IntPtr data, int len); |
|---|
| 863 | public CuculFont(string s) |
|---|
| 864 | { |
|---|
| 865 | IntPtr name = Marshal.StringToHGlobalAnsi(s); |
|---|
| 866 | _font = cucul_load_font(name, 0); |
|---|
| 867 | Marshal.FreeHGlobal(name); |
|---|
| 868 | } |
|---|
| 869 | |
|---|
| 870 | public CuculFont(byte[] buf) |
|---|
| 871 | { |
|---|
| 872 | GCHandle _gch = GCHandle.Alloc(buf, GCHandleType.Pinned); |
|---|
| 873 | _font = cucul_load_font(_gch.AddrOfPinnedObject(), buf.Length); |
|---|
| 874 | } |
|---|
| 875 | |
|---|
| 876 | [DllImport("libcucul.dll", CallingConvention=CallingConvention.Cdecl), |
|---|
| 877 | SuppressUnmanagedCodeSecurity] |
|---|
| 878 | private static extern int cucul_free_font(IntPtr d); |
|---|
| 879 | public void Dispose() |
|---|
| 880 | { |
|---|
| 881 | cucul_free_font(_font); |
|---|
| 882 | _gch.Free(); |
|---|
| 883 | GC.SuppressFinalize(this); |
|---|
| 884 | } |
|---|
| 885 | |
|---|
| 886 | [DllImport("libcucul.dll", CallingConvention=CallingConvention.Cdecl), |
|---|
| 887 | SuppressUnmanagedCodeSecurity] |
|---|
| 888 | private static extern IntPtr cucul_get_font_list(); |
|---|
| 889 | public static string[] getList() |
|---|
| 890 | { |
|---|
| 891 | IntPtr l = cucul_get_font_list(); |
|---|
| 892 | |
|---|
| 893 | int size; |
|---|
| 894 | for(size = 0; true; size++) |
|---|
| 895 | if(Marshal.ReadIntPtr(l, IntPtr.Size * size) == IntPtr.Zero) |
|---|
| 896 | break; |
|---|
| 897 | |
|---|
| 898 | string[] ret = new string[size]; |
|---|
| 899 | for(int i = 0; i < size; i++) |
|---|
| 900 | { |
|---|
| 901 | IntPtr s = Marshal.ReadIntPtr(l, IntPtr.Size * i); |
|---|
| 902 | ret[i] = Marshal.PtrToStringAnsi(s); |
|---|
| 903 | } |
|---|
| 904 | |
|---|
| 905 | return ret; |
|---|
| 906 | } |
|---|
| 907 | |
|---|
| 908 | [DllImport("libcucul.dll", CallingConvention=CallingConvention.Cdecl), |
|---|
| 909 | SuppressUnmanagedCodeSecurity] |
|---|
| 910 | private static extern int cucul_get_font_width(IntPtr font); |
|---|
| 911 | [DllImport("libcucul.dll", CallingConvention=CallingConvention.Cdecl), |
|---|
| 912 | SuppressUnmanagedCodeSecurity] |
|---|
| 913 | private static extern int cucul_get_font_height(IntPtr font); |
|---|
| 914 | public Size Size |
|---|
| 915 | { |
|---|
| 916 | get { return new Size(cucul_get_font_width(_font), |
|---|
| 917 | cucul_get_font_height(_font)); } |
|---|
| 918 | } |
|---|
| 919 | |
|---|
| 920 | [DllImport("libcucul.dll", CallingConvention=CallingConvention.Cdecl), |
|---|
| 921 | SuppressUnmanagedCodeSecurity] |
|---|
| 922 | private static extern IntPtr cucul_get_font_blocks(IntPtr font); |
|---|
| 923 | public int[,] getBlocks() |
|---|
| 924 | { |
|---|
| 925 | IntPtr l = cucul_get_font_blocks(_font); |
|---|
| 926 | |
|---|
| 927 | int size; |
|---|
| 928 | for(size = 1; true; size += 2) |
|---|
| 929 | if(Marshal.ReadIntPtr(l, IntPtr.Size * size) == IntPtr.Zero) |
|---|
| 930 | break; |
|---|
| 931 | |
|---|
| 932 | int[,] ret = new int[size,2]; |
|---|
| 933 | for(int i = 0; i < size; i++) |
|---|
| 934 | { |
|---|
| 935 | ret[i,0] = (int)Marshal.ReadIntPtr(l, IntPtr.Size * i * 2); |
|---|
| 936 | ret[i,1] = (int)Marshal.ReadIntPtr(l, IntPtr.Size * i * 2 + 1); |
|---|
| 937 | } |
|---|
| 938 | |
|---|
| 939 | return ret; |
|---|
| 940 | } |
|---|
| 941 | |
|---|
| 942 | [DllImport("libcucul.dll", CallingConvention=CallingConvention.Cdecl), |
|---|
| 943 | SuppressUnmanagedCodeSecurity] |
|---|
| 944 | private static extern int cucul_render_canvas(IntPtr cv, IntPtr f, |
|---|
| 945 | IntPtr buf, int w, int h, |
|---|
| 946 | int pitch); |
|---|
| 947 | public int Render(CuculCanvas cv, uint[,] buf, int pitch) |
|---|
| 948 | { |
|---|
| 949 | GCHandle gch = GCHandle.Alloc(buf, GCHandleType.Pinned); |
|---|
| 950 | int ret = cucul_render_canvas(cv._c_cv, _font, |
|---|
| 951 | gch.AddrOfPinnedObject(), |
|---|
| 952 | buf.GetLength(0), buf.GetLength(1), |
|---|
| 953 | pitch); |
|---|
| 954 | gch.Free(); |
|---|
| 955 | return ret; |
|---|
| 956 | } |
|---|
| 957 | } |
|---|
| 958 | } |
|---|
| 959 | |
|---|