/packages/ggi/src/ggi.pp

https://github.com/slibre/freepascal · Puppet · 784 lines · 569 code · 215 blank · 0 comment · 23 complexity · f5a7662ebf05149b9db5824e65d07d92 MD5 · raw file

  1. {******************************************************************************
  2. Free Pascal conversion (c) 1999 Sebastian Guenther
  3. LibGGI API interface
  4. Copyright (C) 1997 Jason McMullan [jmcc@ggi-project.org]
  5. Copyright (C) 1997 Steffen Seeger [seeger@ggi-project.org]
  6. Copyright (C) 1998 Andrew Apted [andrew@ggi-project.org]
  7. Copyright (C) 1998 Andreas Beck [becka@ggi-project.org]
  8. Copyright (C) 1998-1999 Marcus Sundberg [marcus@ggi-project.org]
  9. Permission is hereby granted, free of charge, to any person obtaining a
  10. copy of this software and associated documentation files (the "Software"),
  11. to deal in the Software without restriction, including without limitation
  12. the rights to use, copy, modify, merge, publish, distribute, sublicense,
  13. and/or sell copies of the Software, and to permit persons to whom the
  14. Software is furnished to do so, subject to the following conditions:
  15. The above copyright notice and this permission notice shall be included in
  16. all copies or substantial portions of the Software.
  17. THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
  18. IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
  19. FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
  20. THE AUTHOR(S) BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER
  21. IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
  22. CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
  23. ******************************************************************************
  24. *}
  25. {$MODE objfpc}
  26. {$PACKRECORDS C}
  27. {$LINKLIB c}
  28. unit GGI;
  29. interface
  30. uses GII;
  31. const
  32. libggi = 'ggi';
  33. {******************************************************************************
  34. LibGGI datatypes and structures
  35. ******************************************************************************}
  36. GGI_AUTO = 0;
  37. type
  38. TGGICoord = record
  39. x, y: SmallInt;
  40. end;
  41. TGGIPixel = LongWord;
  42. TGGIAttr = LongWord;
  43. const
  44. ATTR_FGCOLOR = $0000FF00; // fgcolor clut index
  45. ATTR_BGCOLOR = $000000FF; // bgcolor clut index
  46. ATTR_NORMAL = $00000000; // normal style
  47. ATTR_HALF = $00010000; // half intensity
  48. ATTR_BRIGHT = $00020000; // high intensity
  49. ATTR_INTENSITY = $00030000; // mask to get intensity
  50. ATTR_UNDERLINE = $00040000; // underline attribute
  51. ATTR_BOLD = $00080000; // bold style
  52. ATTR_ITALIC = $00100000; // italic style
  53. ATTR_REVERSE = $00200000; // reverse fg/bg
  54. ATTR_BLINK = $00800000; // enable blinking
  55. ATTR_FONT = $FF000000; // font table
  56. function ATTR_COLOR(fg, bg: Integer): Integer;
  57. type
  58. PGGIColor = ^TGGIColor;
  59. TGGIColor = record
  60. r, g, b, a: Word;
  61. end;
  62. PGGIClut = ^TGGIClut;
  63. TGGIClut = record
  64. size: Word;
  65. data: PGGIColor;
  66. end;
  67. const GGI_COLOR_PRECISION = 16; // 16 bit per R,G, B value
  68. // Graphtypes
  69. type TGGIGraphType = LongWord;
  70. const
  71. GT_DEPTH_SHIFT = 0;
  72. GT_SIZE_SHIFT = 8;
  73. GT_SUBSCHEME_SHIFT = 16;
  74. GT_SCHEME_SHIFT = 24;
  75. GT_DEPTH_MASK = $ff shl GT_DEPTH_SHIFT;
  76. GT_SIZE_MASK = $ff shl GT_SIZE_SHIFT;
  77. GT_SUBSCHEME_MASK = $ff shl GT_SUBSCHEME_SHIFT;
  78. GT_SCHEME_MASK = $ff shl GT_SCHEME_SHIFT;
  79. // Macros to extract info from a ggi_graphtype.
  80. function GT_DEPTH(x: Integer): Integer;
  81. function GT_SIZE(x: Integer): Integer;
  82. function GT_SUBSCHEME(x: Integer): Integer;
  83. function GT_SCHEME(x: Integer): Integer;
  84. {procedure GT_SETDEPTH(gt, x: Integer);
  85. procedure GT_SETSIZE(gt, x: Integer);
  86. procedure GT_SETSUBSCHEME(gt, x: Integer);
  87. procedure GT_SETSCHEME(gt, x: Integer);}
  88. const
  89. // Enumerated schemes
  90. GT_TEXT = 1 shl GT_SCHEME_SHIFT;
  91. GT_TRUECOLOR = 2 shl GT_SCHEME_SHIFT;
  92. GT_GREYSCALE = 3 shl GT_SCHEME_SHIFT;
  93. GT_PALETTE = 4 shl GT_SCHEME_SHIFT;
  94. GT_STATIC_PALETTE = 5 shl GT_SCHEME_SHIFT;
  95. // Subschemes
  96. GT_SUB_REVERSE_ENDIAN = 1 shl GT_SUBSCHEME_SHIFT;
  97. GT_SUB_HIGHBIT_RIGHT = 2 shl GT_SUBSCHEME_SHIFT;
  98. GT_SUB_PACKED_GETPUT = 4 shl GT_SUBSCHEME_SHIFT;
  99. // Macro that constructs a graphtype
  100. function GT_CONSTRUCT(depth, scheme, size: Integer): Integer;
  101. const
  102. // Common graphtypes
  103. GT_TEXT16 = 4 or GT_TEXT or (16 shl GT_SIZE_SHIFT);
  104. GT_TEXT32 = 8 or GT_TEXT or (32 shl GT_SIZE_SHIFT);
  105. GT_1BIT = 1 or GT_PALETTE or (1 shl GT_SIZE_SHIFT);
  106. GT_2BIT = 2 or GT_PALETTE or (2 shl GT_SIZE_SHIFT);
  107. GT_4BIT = 4 or GT_PALETTE or (4 shl GT_SIZE_SHIFT);
  108. GT_8BIT = 8 or GT_PALETTE or (8 shl GT_SIZE_SHIFT);
  109. GT_15BIT = 15 or GT_TRUECOLOR or (16 shl GT_SIZE_SHIFT);
  110. GT_16BIT = 16 or GT_TRUECOLOR or (16 shl GT_SIZE_SHIFT);
  111. GT_24BIT = 24 or GT_TRUECOLOR or (24 shl GT_SIZE_SHIFT);
  112. GT_32BIT = 24 or GT_TRUECOLOR or (32 shl GT_SIZE_SHIFT);
  113. GT_AUTO = 0;
  114. GT_INVALID = $ffffffff;
  115. // ggi_mode structure
  116. type
  117. TGGIMode = record // requested by user and changed by driver
  118. Frames: LongInt; // frames needed
  119. Visible: TGGICoord; // vis. pixels, may change slightly
  120. Virt: TGGICoord; // virtual pixels, may change
  121. Size: TGGICoord; // size of visible in mm
  122. GraphType: TGGIGraphType; // which mode ?
  123. dpp: TGGICoord; // dots per pixel
  124. end;
  125. {******************************************************************************
  126. LibGGI specific events
  127. ******************************************************************************}
  128. const
  129. GGI_CMDFLAG_LIBGGI = GII_CMDFLAG_EXTERNAL shr 1;
  130. { Tell target that the application should not/should be halted when the
  131. display is unmapped. The default is to halt the application.}
  132. GGICMD_NOHALT_ON_UNMAP = GII_CMDFLAG_EXTERNAL or GGI_CMDFLAG_LIBGGI or GII_CMDFLAG_NODATA or 1;
  133. GGICMD_HALT_ON_UNMAP = GII_CMDFLAG_EXTERNAL or GGI_CMDFLAG_LIBGGI or GII_CMDFLAG_NODATA or 2;
  134. { Requests the application to switch target/mode, or to stop drawing on
  135. the visual.
  136. The latter is only sent if the application has explicitly requested
  137. GGICMD_NOHALT_ON_UNMAP. When a GGI_REQSW_UNMAP request is sent the
  138. application should respond by sending a GGICMD_ACKNOWLEDGE_SWITCH event
  139. as quickly as possible. After the acknowledge event is sent the
  140. application must not draw onto the visual until it recieves an evExpose
  141. event, which tells the application that the visual is mapped back again.
  142. }
  143. GGICMD_REQUEST_SWITCH = GII_CMDFLAG_EXTERNAL or GGI_CMDFLAG_LIBGGI or 1;
  144. // Used for 'request' field in ggi_cmddata_switchrequest
  145. GGI_REQSW_UNMAP = 1;
  146. GGI_REQSW_MODE = 2;
  147. GGI_REQSW_TARGET = 4;
  148. type
  149. TGGICmdDataSwitchRequest = record
  150. Request: LongWord;
  151. Mode: TGGIMode;
  152. target: array[0..63] of Char;
  153. end;
  154. const
  155. GGICMD_ACKNOWLEDGE_SWITCH = GII_CMDFLAG_EXTERNAL or GGI_CMDFLAG_LIBGGI or GII_CMDFLAG_NODATA or 3;
  156. type
  157. TGGIVisual = Pointer;
  158. TGGIResource = Pointer;
  159. // Flags and frames
  160. TGGIFlags = LongWord;
  161. const
  162. GGIFLAG_ASYNC = 1;
  163. {******************************************************************************
  164. Misc macros
  165. ******************************************************************************}
  166. // Swap the bytes in a 16 respective 32 bit unsigned number
  167. function GGI_BYTEREV16(x: Integer): Integer;
  168. function GGI_BYTEREV32(x: LongWord): LongWord;
  169. // Swap the bitgroups in an 8 bit unsigned number
  170. function GGI_BITREV4(x: Integer): Integer;
  171. function GGI_BITREV2(x: Integer): Integer;
  172. function GGI_BITREV1(x: Integer): Integer;
  173. {******************************************************************************
  174. Information that can be returned to user apps
  175. ******************************************************************************}
  176. // Bitmeaning defines
  177. const
  178. GGI_BM_TYPE_NONE = 0; // This bit is not in use
  179. // Bit influences color of displayed pixel
  180. GGI_BM_TYPE_COLOR = $010000;
  181. GGI_BM_SUB_RED = $0100;
  182. GGI_BM_SUB_GREEN = $0200;
  183. GGI_BM_SUB_BLUE = $0300;
  184. GGI_BM_SUB_CYAN = $1000;
  185. GGI_BM_SUB_MAGENTA = $1100;
  186. GGI_BM_SUB_YELLOW = $1200;
  187. GGI_BM_SUB_K = $1300;
  188. GGI_BM_SUB_Y = $2000;
  189. GGI_BM_SUB_U = $2100;
  190. GGI_BM_SUB_V = $2200;
  191. GGI_BM_SUB_CLUT = $f000; // This bit Color or attrib ?
  192. // Bit changes appearance of pixel/glyph
  193. GGI_BM_TYPE_ATTRIB = $020000;
  194. GGI_BM_SUB_ALPHA = $0100;
  195. GGI_BM_SUB_BLINK = $1000;
  196. GGI_BM_SUB_INTENSITY = $1100;
  197. GGI_BM_SUB_UNDERLINE = $1200;
  198. GGI_BM_SUB_BOLD = $1300;
  199. GGI_BM_SUB_ITALIC = $1400;
  200. GGI_BM_SUB_FGCOL = $2000;
  201. GGI_BM_SUB_BGCOL = $2100;
  202. GGI_BM_SUB_TEXNUM = $3000;
  203. GGI_BM_SUB_FONTSEL = $3100; // select different font banks
  204. GGI_BM_SUB_PALSEL = $3200; // select different palettes
  205. GGI_BM_SUB_MODESEL = $3300; // select different palettes
  206. // Bit that influence drawing logic
  207. GGI_BM_TYPE_LOGIC = $030000;
  208. GGI_BM_SUB_ZBUFFER = $0100;
  209. GGI_BM_SUB_WRITEPROT = $1000;
  210. GGI_BM_SUB_WINDOWID = $2000;
  211. // Pixelformat for ggiGet/Put* buffers and pixellinearbuffers */
  212. type
  213. PGGIPixelFormat = ^TGGIPixelFormat;
  214. TGGIPixelFormat = record
  215. depth: Integer; // Number of significant bits
  216. size: Integer; // Physical size in bits
  217. {* Simple and common things first :
  218. *
  219. * Usage of the mask/shift pairs:
  220. * If new_value is the _sizeof(ggi_pixel)*8bit_ value of the thing
  221. * you want to set, you do
  222. *
  223. * *pointer &= ~???_mask; // Mask out old bits
  224. * *pointer |= (new_value>>shift) & ???_mask;
  225. *
  226. * The reason to use 32 bit and "downshifting" is alignment
  227. * and extensibility. You can easily adjust to other datasizes
  228. * with a simple addition ...
  229. *}
  230. // Simple colors:
  231. red_mask: TGGIPixel; // Bitmask of red bits
  232. red_shift: Integer; // Shift for red bits
  233. green_mask: TGGIPixel; // Bitmask of green bits
  234. green_shift: Integer; // Shift for green bits
  235. blue_mask: TGGIPixel; // Bitmask of blue bits
  236. blue_shift: Integer; // Shift for blue bits
  237. // A few common attributes:
  238. alpha_mask: TGGIPixel; // Bitmask of alphachannel bits
  239. alpha_shift: Integer; // Shift for alpha bits
  240. clut_mask: TGGIPixel; // Bitmask of bits for the clut
  241. clut_shift: Integer; // Shift for bits for the clut
  242. fg_mask: TGGIPixel; // Bitmask of foreground color
  243. fg_shift: Integer; // Shift for foreground color
  244. bg_mask: TGGIPixel; // Bitmask of background color
  245. bg_shift: Integer; // Shift for background color
  246. texture_mask: TGGIPixel; // Bitmask of the texture (for
  247. // textmodes - the actual character)
  248. texture_shift: Integer; // Shift for texture
  249. // Now if this does not suffice you might want to parse the following
  250. // to find out what each bit does:
  251. bitmeaning: array[0..SizeOf(TGGIPixel) * 8 - 1] of LongWord;
  252. // Shall we keep those?
  253. flags: LongWord; // Pixelformat flags
  254. stdformat: LongWord; // Standard format identifier
  255. {* This one has only one use for the usermode application:
  256. * To quickly check, if two buffers are identical. If both
  257. * stdformats are the same and _NOT_ 0 (which means "WEIRD"),
  258. * you may use things like memcpy between them which will have
  259. * the desired effect ...
  260. *}
  261. end;
  262. const
  263. // Pixelformat flags
  264. GGI_PF_REVERSE_ENDIAN = 1;
  265. GGI_PF_HIGHBIT_RIGHT = 2;
  266. GGI_PF_HAM = 4;
  267. GGI_PF_EXTENDED = 8;
  268. {******************************************************************************
  269. DirectBuffer
  270. ******************************************************************************}
  271. type
  272. TGGIBufferLayout = (
  273. blPixelLinearBuffer,
  274. blPixelPlanarBuffer,
  275. blExtended,
  276. blLastBufferLayout
  277. );
  278. PGGIPixelLinearBuffer = ^TGGIPixelLinearBuffer;
  279. TGGIPixelLinearBuffer = record
  280. stride: Integer; // bytes per row
  281. pixelformat: PGGIPixelFormat; // format of the pixels
  282. end;
  283. PGGIPixelPlanarBuffer = ^TGGIPixelPlanarBuffer;
  284. TGGIPixelPlanarBuffer = record
  285. next_line: Integer; // bytes until next line
  286. next_plane: Integer; // bytes until next plane
  287. pixelformat: PGGIPixelFormat; // format of the pixels
  288. end;
  289. // Buffer types
  290. const
  291. GGI_DB_NORMAL = 1; // "frame" is valid when set
  292. GGI_DB_EXTENDED = 2;
  293. GGI_DB_MULTI_LEFT = 4;
  294. GGI_DB_MULTI_RIGHT = 8;
  295. // Flags that may be 'or'ed with the buffer type
  296. GGI_DB_SIMPLE_PLB = $01000000;
  297. { GGI_DB_SIMPLE_PLB means that the buffer has the following properties:
  298. type = GGI_DB_NORMAL
  299. read = write
  300. noaccess = 0
  301. align = 0
  302. layout = blPixelLinearBuffer
  303. }
  304. type
  305. PGGIDirectBuffer = ^TGGIDirectBuffer;
  306. TGGIDirectBuffer = record
  307. BufferType: LongWord; // buffer type
  308. frame: Integer; // framenumber (GGI_DB_NORMAL)
  309. // access info
  310. resource: TGGIResource; // If non-NULL you must acquire the
  311. // buffer before using it
  312. read: Pointer; // buffer address for reads
  313. write:Pointer; // buffer address for writes
  314. page_size: LongWord; // zero for true linear buffers
  315. noaccess: LongWord;
  316. {bitfield. bit x set means you may _not_ access this DB at the
  317. width of 2^x bytes. Usually 0, but _check_ it.}
  318. align: LongWord;
  319. {bitfield. bit x set means you may only access this DB at the
  320. width of 2^x bytes, when the access is aligned to a multiple
  321. of 2^x. Note that bit 0 is a bit bogus here, but it should
  322. be always 0, as then ((noaccess|align)==0) is a quick check
  323. for "no restrictions". }
  324. layout: TGGIBufferLayout;
  325. // The actual buffer info. Depends on layout.
  326. buffer: record
  327. case Integer of
  328. 0: (plb: TGGIPixelLinearBuffer);
  329. 1: (plan: TGGIPixelPlanarBuffer);
  330. 2: (extended: Pointer);
  331. end;
  332. end;
  333. {******************************************************************************
  334. Resource management
  335. ******************************************************************************}
  336. // Access types
  337. const
  338. GGI_ACTYPE_READ = 1 shl 0;
  339. GGI_ACTYPE_WRITE = 1 shl 1;
  340. {******************************************************************************
  341. LibGGI function definitions
  342. ******************************************************************************}
  343. // Enter and leave the library
  344. function ggiInit: Integer; cdecl; external libggi;
  345. procedure ggiExit; cdecl; external libggi;
  346. procedure ggiPanic(format: PChar; args: array of const); cdecl; external libggi;
  347. // Open a new visual - use display 'NULL' for the default visual
  348. function ggiOpen(display: PChar; args: array of const): TGGIVisual; cdecl; external libggi;
  349. function ggiClose(vis: TGGIVisual): Integer; cdecl; external libggi;
  350. // Get/Set info
  351. function ggiSetFlags(vis: TGGIVisual; flags: TGGIFlags): Integer; cdecl; external libggi;
  352. function ggiGetFlags(vis: TGGIVisual): TGGIFlags; cdecl; external libggi;
  353. function ggiAddFlags(vis: TGGIVisual; flags: TGGIFlags): Integer;
  354. function ggiRemoveFlags(vis: TGGIVisual; flags: TGGIFlags): Integer;
  355. function ggiGetPixelFormat(vis: TGGIVisual): PGGIPixelFormat; cdecl; external libggi;
  356. // DirectBuffer (DB) functions
  357. function ggiDBGetNumBuffers(vis: TGGIVisual): Integer; cdecl; external libggi;
  358. function ggiDBGetBuffer(vis: TGGIVisual; bufnum: Integer): PGGIDirectBuffer; cdecl; external libggi;
  359. // Resource functions
  360. function ggiResourceAcquire(res: TGGIResource; actype: LongWord): Integer;
  361. function ggiResourceRelease(res: TGGIResource): Integer;
  362. function ggiResourceFastAcquire(res: TGGIResource; actype: LongWord): Integer; cdecl; external libggi;
  363. function ggiResourceFastRelease(res: TGGIResource): Integer; cdecl; external libggi;
  364. // Library management
  365. const GGI_MAX_APILEN = 1024;
  366. function ggiGetAPI(vis: TGGIVisual; num: Integer; APIName, arguments: PChar): Integer; cdecl; external libggi;
  367. const GGI_CHG_APILIST = 1;
  368. function ggiIndicateChange(vis: TGGIVisual; WhatChanged: Integer): Integer; cdecl; external libggi;
  369. // Mode management
  370. function ggiSetMode(visual: TGGIVisual; var tm: TGGIMode): Integer; cdecl; external libggi;
  371. function ggiGetMode(visual: TGGIVisual; var tm: TGGIMode): Integer; cdecl; external libggi;
  372. function ggiCheckMode(visual: TGGIVisual; var tm: TGGIMode): Integer; cdecl; external libggi;
  373. function ggiSetTextMode(visual: TGGIVisual; cols, rows, vcols, vrows, fontx, fonty: Integer; AType: TGGIGraphType): Integer; cdecl; external libggi;
  374. function ggiCheckTextMode(visual: TGGIVisual; cols, rows, vcols, vrows, fontx, fonty: Integer; var SuggestedMode: TGGIMode): Integer; cdecl; external libggi;
  375. function ggiSetGraphMode(visual: TGGIVisual; x, y, xv, yv: Integer; AType: TGGIGraphType): Integer; cdecl; external libggi;
  376. function ggiCheckGraphMode(visual: TGGIVisual; x, y, xv, yv: Integer; AType: TGGIGraphType; var SuggestedMode: TGGIMode): Integer; cdecl; external libggi;
  377. function ggiSetSimpleMode(visual: TGGIVisual; xsize, ysize, frames: Integer; AType: TGGIGraphType): Integer; cdecl; external libggi;
  378. function ggiCheckSimpleMode(visual: TGGIVisual; xsize, ysize, frames: Integer; AType: TGGIGraphType; var md: TGGIMode): Integer; cdecl; external libggi;
  379. // Print all members of the mode struct
  380. function ggiSPrintMode(s: PChar; var m: TGGIMode): Integer; cdecl; external libggi;
  381. // function ggiFPrintMode(s: PFile; var m: TGGIMode): Integer; cdecl; external libggi;
  382. // #define ggiPrintMode(m) ggiFPrintMode(stdout,(m))
  383. // Fill a mode struct from the text string s
  384. function ggiParseMode(s: PChar; var m: TGGIMode): Integer; cdecl; external libggi;
  385. // Flush all pending operations to the display device
  386. // Normal flush
  387. function ggiFlush(vis: TGGIVisual): Integer; cdecl; external libggi;
  388. // Flush only the specified region if it would improve performance
  389. function ggiFlushRegion(vis: TGGIVisual; x, y, w, h: Integer): Integer; cdecl; external libggi;
  390. // Graphics context
  391. function ggiSetGCForeground(vis: TGGIVisual; const Color: TGGIPixel): Integer; cdecl; external libggi;
  392. function ggiGetGCForeground(vis: TGGIVisual; var Color: TGGIPixel): Integer; cdecl; external libggi;
  393. function ggiSetGCBackground(vis: TGGIVisual; const Color: TGGIPixel): Integer; cdecl; external libggi;
  394. function ggiGetGCBackground(vis: TGGIVisual; var Color: TGGIPixel): Integer; cdecl; external libggi;
  395. function ggiSetGCClipping(vis: TGGIVisual; left, top, right, bottom: Integer): Integer; cdecl; external libggi;
  396. function ggiGetGCClipping(vis: TGGIVisual; var left, top, right, bottom: Integer): Integer; cdecl; external libggi;
  397. // Color palette manipulation
  398. function ggiMapColor(vis: TGGIVisual; var Color: TGGIColor): TGGIPixel; cdecl; external libggi;
  399. function ggiUnmapPixel(vis: TGGIVisual; pixel: TGGIPixel; var Color: TGGIColor): Integer; cdecl; external libggi;
  400. function ggiPackColors(vis: TGGIVisual; var buf; var cols: TGGIColor; len: Integer): Integer; cdecl; external libggi;
  401. function ggiUnpackPixels(vis: TGGIVisual; var buf; var cols: TGGIColor; len: Integer): Integer; cdecl; external libggi;
  402. function ggiGetPalette(vis: TGGIVisual; s, len: Integer; var cmap: TGGIColor): Integer; cdecl; external libggi;
  403. function ggiSetPalette(vis: TGGIVisual; s, len: Integer; var cmap: TGGIColor): Integer; cdecl; external libggi;
  404. function ggiSetColorfulPalette(vis: TGGIVisual): Integer; cdecl; external libggi;
  405. const GGI_PALETTE_DONTCARE = -1;
  406. // Gamma map manipulation
  407. function ggiGetGamma(vis: TGGIVisual; var r, g, b: Double): Integer; cdecl; external libggi;
  408. function ggiSetGamma(vis: TGGIVisual; r, g, b: Double): Integer; cdecl; external libggi;
  409. function ggiGetGammaMap(vis: TGGIVisual; s, len: Integer; var gammamap: TGGIColor): Integer; cdecl; external libggi;
  410. function ggiSetGammaMap(vis: TGGIVisual; s, len: Integer; var gammamap: TGGIColor): Integer; cdecl; external libggi;
  411. // Origin handling
  412. function ggiSetOrigin(vis: TGGIVisual; x, y: Integer): Integer; cdecl; external libggi;
  413. function ggiGetOrigin(vis: TGGIVisual; var x, y: Integer): Integer; cdecl; external libggi;
  414. // Frame handling
  415. function ggiSetDisplayFrame(vis: TGGIVisual; FrameNo: Integer): Integer; cdecl; external libggi;
  416. function ggiSetReadFrame(vis: TGGIVisual; FrameNo: Integer): Integer; cdecl; external libggi;
  417. function ggiSetWriteFrame(vis: TGGIVisual; FrameNo: Integer): Integer; cdecl; external libggi;
  418. function ggiGetDisplayFrame(vis: TGGIVisual): Integer; cdecl; external libggi;
  419. function ggiGetReadFrame(vis: TGGIVisual): Integer; cdecl; external libggi;
  420. function ggiGetWriteFrame(vis: TGGIVisual): Integer; cdecl; external libggi;
  421. // Generic drawing routines
  422. function ggiFillscreen(vis: TGGIVisual): Integer; cdecl; external libggi;
  423. function ggiDrawPixel(vis: TGGIVisual; x, y: Integer): Integer; cdecl; external libggi;
  424. function ggiPutPixel(vis: TGGIVisual; x, y: Integer; pixel: TGGIPixel): Integer; cdecl; external libggi;
  425. function ggiGetPixel(vis: TGGIVisual; x, y: Integer; var pixel: TGGIPixel): Integer; cdecl; external libggi;
  426. function ggiDrawLine(vis: TGGIVisual; x, y, xe, ye: Integer): Integer; cdecl; external libggi;
  427. function ggiDrawHLine(vis: TGGIVisual; x, y, w: Integer): Integer; cdecl; external libggi;
  428. function ggiPutHLine(vis: TGGIVisual; x, y, w: Integer; var buf): Integer; cdecl; external libggi;
  429. function ggiGetHLine(vis: TGGIVisual; x, y, w: Integer; var buf): Integer; cdecl; external libggi;
  430. function ggiDrawVLine(vis: TGGIVisual; x, y, h: Integer): Integer; cdecl; external libggi;
  431. function ggiPutVLine(vis: TGGIVisual; x, y, h: Integer; var buf): Integer; cdecl; external libggi;
  432. function ggiGetVLine(vis: TGGIVisual; x, y, h: Integer; var buf): Integer; cdecl; external libggi;
  433. function ggiDrawBox(vis: TGGIVisual; x, y, w, h: Integer): Integer; cdecl; external libggi;
  434. function ggiPutBox(vis: TGGIVisual; x, y, w, h: Integer; var buffer): Integer; cdecl; external libggi;
  435. function ggiGetBox(vis: TGGIVisual; x, y, w, h: Integer; var buffer): Integer; cdecl; external libggi;
  436. function ggiCopyBox(vis: TGGIVisual; x, y, w, h, nx, ny: Integer): Integer; cdecl; external libggi;
  437. function ggiCrossBlit(src: TGGIVisual; sx, sy, w, h: Integer; dst: TGGIVisual; dx, dy: Integer): Integer; cdecl; external libggi;
  438. // Text drawing routines
  439. function ggiPutc(vis: TGGIVisual; x, y: Integer; c: Char): Integer; cdecl; external libggi;
  440. function ggiPuts(vis: TGGIVisual; x, y: Integer; str: PChar): Integer; cdecl; external libggi;
  441. function ggiGetCharSize(vis: TGGIVisual; var width, height: Integer): Integer; cdecl; external libggi;
  442. // Event handling
  443. //###function ggiEventPoll(vis: TGGIVisual; mask: TGIIEventMask; var t: TTimeVal): TGIIEventMask; cdecl; external libggi;
  444. function ggiEventsQueued(vis: TGGIVisual; mask: TGIIEventMask): Integer; cdecl; external libggi;
  445. function ggiEventRead(vis: TGGIVisual; var Event: TGIIEvent; mask: TGIIEventMask): Integer; cdecl; external libggi;
  446. function ggiSetEventMask(vis: TGGIVisual; EventMask: TGIIEventMask): Integer; cdecl; external libggi;
  447. function ggiGetEventMask(vis: TGGIVisual): TGIIEventMask; cdecl; external libggi;
  448. function ggiEventSend(vis: TGGIVisual; var Event: TGIIEvent): Integer; cdecl; external libggi;
  449. function ggiJoinInputs(vis: TGGIVisual; Input: TGIIInput): TGIIInput; cdecl; external libggi;
  450. function ggiAddEventMask(vis: TGGIVisual; Mask: TGIIEventMask): Integer;
  451. function ggiRemoveEventMask(vis: TGGIVisual; Mask: TGIIEventMask): Integer;
  452. // Convenience functions
  453. function ggiKbhit(vis: TGGIVisual): Integer; cdecl; external libggi;
  454. function ggiGetc(vis: TGGIVisual): Integer; cdecl; external libggi;
  455. // Extension handling
  456. type
  457. TGGILibID = Pointer;
  458. TGGIExtID = Integer; {Don't rely on that !}
  459. TGGIParamChangeProc = function(Visual: TGGIVisual; WhatChanged: Integer): Integer;
  460. function ggiExtensionRegister(name: PChar; size: Integer;
  461. ParamChange: TGGIParamChangeProc): TGGIExtID; cdecl; external libggi;
  462. function ggiExtensionUnregister(id: TGGIExtID): Integer; cdecl; external libggi;
  463. function ggiExtensionAttach(Visual: TGGIVisual; id: TGGIExtID): Integer; cdecl; external libggi;
  464. function ggiExtensionDetach(Visual: TGGIVisual; id: TGGIExtID): Integer; cdecl; external libggi;
  465. function ggiExtensionLoadDL(Visual: TGGIVisual; filename, args: PChar; ArgPtr: Pointer): TGGILibID; cdecl; external libggi;
  466. // ===================================================================
  467. // ===================================================================
  468. implementation
  469. function ATTR_COLOR(fg, bg: Integer): Integer;
  470. begin
  471. Result := (bg and $ff) or ((fg and $ff) shl 8);
  472. end;
  473. function GT_DEPTH(x: Integer): Integer;
  474. begin
  475. Result := (x and GT_DEPTH_MASK) shr GT_DEPTH_SHIFT;
  476. end;
  477. function GT_SIZE(x: Integer): Integer;
  478. begin
  479. Result := (x and GT_SIZE_MASK) shr GT_SIZE_SHIFT;
  480. end;
  481. function GT_SUBSCHEME(x: Integer): Integer;
  482. begin
  483. Result := x and GT_SUBSCHEME_MASK;
  484. end;
  485. function GT_SCHEME(x: Integer): Integer;
  486. begin
  487. Result := x and GT_SCHEME_MASK;
  488. end;
  489. function GT_CONSTRUCT(depth, scheme, size: Integer): Integer;
  490. begin
  491. Result := depth or scheme or (size shl GT_SIZE_SHIFT);
  492. end;
  493. function GGI_BYTEREV16(x: Integer): Integer;
  494. begin
  495. Result := (x shl 8) or (x shr 8);
  496. end;
  497. function GGI_BYTEREV32(x: LongWord): LongWord;
  498. begin
  499. Result := (x shl 24) or ((x and $ff00) shl 8) or
  500. ((x and $ff0000) shr 8) or (x shr 24);
  501. end;
  502. function GGI_BITREV4(x: Integer): Integer;
  503. begin
  504. Result := (x shr 4) or (x shl 4);
  505. end;
  506. function GGI_BITREV2(x: Integer): Integer;
  507. begin
  508. Result := (x shr 6) or ((x and $30) shr 2) or ((x and $0c) shl 2) or (x shl 6);
  509. end;
  510. function GGI_BITREV1(x: Integer): Integer;
  511. begin
  512. Result := (x shr 7) or ((x and $40) shr 5) or ((x and $20) shr 3) or
  513. ((x and $10) shr 1) or ((x and 8) shl 1) or ((x and 4) shl 3) or
  514. ((x and 2) shl 4) or (x shl 7);
  515. end;
  516. function ggiAddFlags(vis: TGGIVisual; flags: TGGIFlags): Integer;
  517. begin
  518. Result := ggiSetFlags(vis, ggiGetFlags(vis) or flags);
  519. end;
  520. function ggiRemoveFlags(vis: TGGIVisual; flags: TGGIFlags): Integer;
  521. begin
  522. Result := ggiSetFlags(vis, ggiGetFlags(vis) and not flags);
  523. end;
  524. function ggiResourceAcquire(res: TGGIResource; actype: LongWord): Integer;
  525. begin
  526. if res = nil then Result := 0
  527. else Result := ggiResourceFastAcquire(res, actype);
  528. end;
  529. function ggiResourceRelease(res: TGGIResource): Integer;
  530. begin
  531. if res = nil then Result := 0
  532. else Result := ggiResourceFastRelease(res);
  533. end;
  534. function ggiAddEventMask(vis: TGGIVisual; Mask: TGIIEventMask): Integer;
  535. begin
  536. Result := ggiSetEventMask(vis, ggiGetEventMask(vis) or mask);
  537. end;
  538. function ggiRemoveEventMask(vis: TGGIVisual; Mask: TGIIEventMask): Integer;
  539. begin
  540. Result := ggiSetEventMask(vis, ggiGetEventMask(vis) and not mask);
  541. end;
  542. end.